repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
felixfbecker/php-language-server | src/SignatureHelpProvider.php | SignatureHelpProvider.findActiveParameter | private function findActiveParameter(
Node\DelimitedList\ArgumentExpressionList $argumentExpressionList,
Position $position,
PhpDocument $doc
): int {
$args = $argumentExpressionList->children;
$i = 0;
$found = null;
foreach ($args as $arg) {
if ($arg instanceof Node) {
$start = $arg->getFullStart();
$end = $arg->getEndPosition();
} else {
$start = $arg->fullStart;
$end = $start + $arg->length;
}
$offset = $position->toOffset($doc->getContent());
if ($offset >= $start && $offset <= $end) {
$found = $i;
break;
}
if ($arg instanceof Node) {
++$i;
}
}
if ($found === null) {
$found = $i;
}
return $found;
} | php | private function findActiveParameter(
Node\DelimitedList\ArgumentExpressionList $argumentExpressionList,
Position $position,
PhpDocument $doc
): int {
$args = $argumentExpressionList->children;
$i = 0;
$found = null;
foreach ($args as $arg) {
if ($arg instanceof Node) {
$start = $arg->getFullStart();
$end = $arg->getEndPosition();
} else {
$start = $arg->fullStart;
$end = $start + $arg->length;
}
$offset = $position->toOffset($doc->getContent());
if ($offset >= $start && $offset <= $end) {
$found = $i;
break;
}
if ($arg instanceof Node) {
++$i;
}
}
if ($found === null) {
$found = $i;
}
return $found;
} | [
"private",
"function",
"findActiveParameter",
"(",
"Node",
"\\",
"DelimitedList",
"\\",
"ArgumentExpressionList",
"$",
"argumentExpressionList",
",",
"Position",
"$",
"position",
",",
"PhpDocument",
"$",
"doc",
")",
":",
"int",
"{",
"$",
"args",
"=",
"$",
"argumentExpressionList",
"->",
"children",
";",
"$",
"i",
"=",
"0",
";",
"$",
"found",
"=",
"null",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"$",
"arg",
"instanceof",
"Node",
")",
"{",
"$",
"start",
"=",
"$",
"arg",
"->",
"getFullStart",
"(",
")",
";",
"$",
"end",
"=",
"$",
"arg",
"->",
"getEndPosition",
"(",
")",
";",
"}",
"else",
"{",
"$",
"start",
"=",
"$",
"arg",
"->",
"fullStart",
";",
"$",
"end",
"=",
"$",
"start",
"+",
"$",
"arg",
"->",
"length",
";",
"}",
"$",
"offset",
"=",
"$",
"position",
"->",
"toOffset",
"(",
"$",
"doc",
"->",
"getContent",
"(",
")",
")",
";",
"if",
"(",
"$",
"offset",
">=",
"$",
"start",
"&&",
"$",
"offset",
"<=",
"$",
"end",
")",
"{",
"$",
"found",
"=",
"$",
"i",
";",
"break",
";",
"}",
"if",
"(",
"$",
"arg",
"instanceof",
"Node",
")",
"{",
"++",
"$",
"i",
";",
"}",
"}",
"if",
"(",
"$",
"found",
"===",
"null",
")",
"{",
"$",
"found",
"=",
"$",
"i",
";",
"}",
"return",
"$",
"found",
";",
"}"
] | Given a position and arguments, finds the "active" argument at the position
@param Node\DelimitedList\ArgumentExpressionList $argumentExpressionList The argument expression list
@param Position $position The position to detect the active argument from
@param PhpDocument $doc The document that contains the expression
@return int | [
"Given",
"a",
"position",
"and",
"arguments",
"finds",
"the",
"active",
"argument",
"at",
"the",
"position"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/SignatureHelpProvider.php#L156-L185 | train |
felixfbecker/php-language-server | src/PhpDocument.php | PhpDocument.getReferenceNodesByFqn | public function getReferenceNodesByFqn(string $fqn)
{
return isset($this->referenceNodes) && isset($this->referenceNodes[$fqn]) ? $this->referenceNodes[$fqn] : null;
} | php | public function getReferenceNodesByFqn(string $fqn)
{
return isset($this->referenceNodes) && isset($this->referenceNodes[$fqn]) ? $this->referenceNodes[$fqn] : null;
} | [
"public",
"function",
"getReferenceNodesByFqn",
"(",
"string",
"$",
"fqn",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"referenceNodes",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"referenceNodes",
"[",
"$",
"fqn",
"]",
")",
"?",
"$",
"this",
"->",
"referenceNodes",
"[",
"$",
"fqn",
"]",
":",
"null",
";",
"}"
] | Get all references of a fully qualified name
@param string $fqn The fully qualified name of the symbol
@return Node[] | [
"Get",
"all",
"references",
"of",
"a",
"fully",
"qualified",
"name"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/PhpDocument.php#L114-L117 | train |
felixfbecker/php-language-server | src/PhpDocument.php | PhpDocument.updateContent | public function updateContent(string $content)
{
// Unregister old definitions
if (isset($this->definitions)) {
foreach ($this->definitions as $fqn => $definition) {
$this->index->removeDefinition($fqn);
}
}
// Unregister old references
if (isset($this->referenceNodes)) {
foreach ($this->referenceNodes as $fqn => $node) {
$this->index->removeReferenceUri($fqn, $this->uri);
}
}
$this->referenceNodes = null;
$this->definitions = null;
$this->definitionNodes = null;
$treeAnalyzer = new TreeAnalyzer($this->parser, $content, $this->docBlockFactory, $this->definitionResolver, $this->uri);
$this->diagnostics = $treeAnalyzer->getDiagnostics();
$this->definitions = $treeAnalyzer->getDefinitions();
$this->definitionNodes = $treeAnalyzer->getDefinitionNodes();
$this->referenceNodes = $treeAnalyzer->getReferenceNodes();
foreach ($this->definitions as $fqn => $definition) {
$this->index->setDefinition($fqn, $definition);
}
// Register this document on the project for references
foreach ($this->referenceNodes as $fqn => $nodes) {
// Cast the key to string. If (string)'2' is set as an array index, it will read out as (int)2. We must
// deal with incorrect code, so this is a valid scenario.
$this->index->addReferenceUri((string)$fqn, $this->uri);
}
$this->sourceFileNode = $treeAnalyzer->getSourceFileNode();
} | php | public function updateContent(string $content)
{
// Unregister old definitions
if (isset($this->definitions)) {
foreach ($this->definitions as $fqn => $definition) {
$this->index->removeDefinition($fqn);
}
}
// Unregister old references
if (isset($this->referenceNodes)) {
foreach ($this->referenceNodes as $fqn => $node) {
$this->index->removeReferenceUri($fqn, $this->uri);
}
}
$this->referenceNodes = null;
$this->definitions = null;
$this->definitionNodes = null;
$treeAnalyzer = new TreeAnalyzer($this->parser, $content, $this->docBlockFactory, $this->definitionResolver, $this->uri);
$this->diagnostics = $treeAnalyzer->getDiagnostics();
$this->definitions = $treeAnalyzer->getDefinitions();
$this->definitionNodes = $treeAnalyzer->getDefinitionNodes();
$this->referenceNodes = $treeAnalyzer->getReferenceNodes();
foreach ($this->definitions as $fqn => $definition) {
$this->index->setDefinition($fqn, $definition);
}
// Register this document on the project for references
foreach ($this->referenceNodes as $fqn => $nodes) {
// Cast the key to string. If (string)'2' is set as an array index, it will read out as (int)2. We must
// deal with incorrect code, so this is a valid scenario.
$this->index->addReferenceUri((string)$fqn, $this->uri);
}
$this->sourceFileNode = $treeAnalyzer->getSourceFileNode();
} | [
"public",
"function",
"updateContent",
"(",
"string",
"$",
"content",
")",
"{",
"// Unregister old definitions",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"definitions",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"definitions",
"as",
"$",
"fqn",
"=>",
"$",
"definition",
")",
"{",
"$",
"this",
"->",
"index",
"->",
"removeDefinition",
"(",
"$",
"fqn",
")",
";",
"}",
"}",
"// Unregister old references",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"referenceNodes",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"referenceNodes",
"as",
"$",
"fqn",
"=>",
"$",
"node",
")",
"{",
"$",
"this",
"->",
"index",
"->",
"removeReferenceUri",
"(",
"$",
"fqn",
",",
"$",
"this",
"->",
"uri",
")",
";",
"}",
"}",
"$",
"this",
"->",
"referenceNodes",
"=",
"null",
";",
"$",
"this",
"->",
"definitions",
"=",
"null",
";",
"$",
"this",
"->",
"definitionNodes",
"=",
"null",
";",
"$",
"treeAnalyzer",
"=",
"new",
"TreeAnalyzer",
"(",
"$",
"this",
"->",
"parser",
",",
"$",
"content",
",",
"$",
"this",
"->",
"docBlockFactory",
",",
"$",
"this",
"->",
"definitionResolver",
",",
"$",
"this",
"->",
"uri",
")",
";",
"$",
"this",
"->",
"diagnostics",
"=",
"$",
"treeAnalyzer",
"->",
"getDiagnostics",
"(",
")",
";",
"$",
"this",
"->",
"definitions",
"=",
"$",
"treeAnalyzer",
"->",
"getDefinitions",
"(",
")",
";",
"$",
"this",
"->",
"definitionNodes",
"=",
"$",
"treeAnalyzer",
"->",
"getDefinitionNodes",
"(",
")",
";",
"$",
"this",
"->",
"referenceNodes",
"=",
"$",
"treeAnalyzer",
"->",
"getReferenceNodes",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"definitions",
"as",
"$",
"fqn",
"=>",
"$",
"definition",
")",
"{",
"$",
"this",
"->",
"index",
"->",
"setDefinition",
"(",
"$",
"fqn",
",",
"$",
"definition",
")",
";",
"}",
"// Register this document on the project for references",
"foreach",
"(",
"$",
"this",
"->",
"referenceNodes",
"as",
"$",
"fqn",
"=>",
"$",
"nodes",
")",
"{",
"// Cast the key to string. If (string)'2' is set as an array index, it will read out as (int)2. We must",
"// deal with incorrect code, so this is a valid scenario.",
"$",
"this",
"->",
"index",
"->",
"addReferenceUri",
"(",
"(",
"string",
")",
"$",
"fqn",
",",
"$",
"this",
"->",
"uri",
")",
";",
"}",
"$",
"this",
"->",
"sourceFileNode",
"=",
"$",
"treeAnalyzer",
"->",
"getSourceFileNode",
"(",
")",
";",
"}"
] | Updates the content on this document.
Re-parses a source file, updates symbols and reports parsing errors
that may have occurred as diagnostics.
@param string $content
@return void | [
"Updates",
"the",
"content",
"on",
"this",
"document",
".",
"Re",
"-",
"parses",
"a",
"source",
"file",
"updates",
"symbols",
"and",
"reports",
"parsing",
"errors",
"that",
"may",
"have",
"occurred",
"as",
"diagnostics",
"."
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/PhpDocument.php#L127-L169 | train |
felixfbecker/php-language-server | src/PhpDocument.php | PhpDocument.getNodeAtPosition | public function getNodeAtPosition(Position $position)
{
if ($this->sourceFileNode === null) {
return null;
}
$offset = $position->toOffset($this->sourceFileNode->getFileContents());
$node = $this->sourceFileNode->getDescendantNodeAtPosition($offset);
if ($node !== null && $node->getStart() > $offset) {
return null;
}
return $node;
} | php | public function getNodeAtPosition(Position $position)
{
if ($this->sourceFileNode === null) {
return null;
}
$offset = $position->toOffset($this->sourceFileNode->getFileContents());
$node = $this->sourceFileNode->getDescendantNodeAtPosition($offset);
if ($node !== null && $node->getStart() > $offset) {
return null;
}
return $node;
} | [
"public",
"function",
"getNodeAtPosition",
"(",
"Position",
"$",
"position",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sourceFileNode",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"offset",
"=",
"$",
"position",
"->",
"toOffset",
"(",
"$",
"this",
"->",
"sourceFileNode",
"->",
"getFileContents",
"(",
")",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"sourceFileNode",
"->",
"getDescendantNodeAtPosition",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"node",
"!==",
"null",
"&&",
"$",
"node",
"->",
"getStart",
"(",
")",
">",
"$",
"offset",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"node",
";",
"}"
] | Returns the node at a specified position
@param Position $position
@return Node|null | [
"Returns",
"the",
"node",
"at",
"a",
"specified",
"position"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/PhpDocument.php#L217-L229 | train |
felixfbecker/php-language-server | src/PhpDocument.php | PhpDocument.getRange | public function getRange(Range $range)
{
$content = $this->getContent();
$start = $range->start->toOffset($content);
$length = $range->end->toOffset($content) - $start;
return substr($content, $start, $length);
} | php | public function getRange(Range $range)
{
$content = $this->getContent();
$start = $range->start->toOffset($content);
$length = $range->end->toOffset($content) - $start;
return substr($content, $start, $length);
} | [
"public",
"function",
"getRange",
"(",
"Range",
"$",
"range",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"getContent",
"(",
")",
";",
"$",
"start",
"=",
"$",
"range",
"->",
"start",
"->",
"toOffset",
"(",
"$",
"content",
")",
";",
"$",
"length",
"=",
"$",
"range",
"->",
"end",
"->",
"toOffset",
"(",
"$",
"content",
")",
"-",
"$",
"start",
";",
"return",
"substr",
"(",
"$",
"content",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"}"
] | Returns a range of the content
@param Range $range
@return string|null | [
"Returns",
"a",
"range",
"of",
"the",
"content"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/PhpDocument.php#L237-L243 | train |
felixfbecker/php-language-server | src/Factory/LocationFactory.php | LocationFactory.fromNode | public static function fromNode(Node $node): Location
{
$range = PositionUtilities::getRangeFromPosition(
$node->getStart(),
$node->getWidth(),
$node->getFileContents()
);
return new Location($node->getUri(), new Range(
new Position($range->start->line, $range->start->character),
new Position($range->end->line, $range->end->character)
));
} | php | public static function fromNode(Node $node): Location
{
$range = PositionUtilities::getRangeFromPosition(
$node->getStart(),
$node->getWidth(),
$node->getFileContents()
);
return new Location($node->getUri(), new Range(
new Position($range->start->line, $range->start->character),
new Position($range->end->line, $range->end->character)
));
} | [
"public",
"static",
"function",
"fromNode",
"(",
"Node",
"$",
"node",
")",
":",
"Location",
"{",
"$",
"range",
"=",
"PositionUtilities",
"::",
"getRangeFromPosition",
"(",
"$",
"node",
"->",
"getStart",
"(",
")",
",",
"$",
"node",
"->",
"getWidth",
"(",
")",
",",
"$",
"node",
"->",
"getFileContents",
"(",
")",
")",
";",
"return",
"new",
"Location",
"(",
"$",
"node",
"->",
"getUri",
"(",
")",
",",
"new",
"Range",
"(",
"new",
"Position",
"(",
"$",
"range",
"->",
"start",
"->",
"line",
",",
"$",
"range",
"->",
"start",
"->",
"character",
")",
",",
"new",
"Position",
"(",
"$",
"range",
"->",
"end",
"->",
"line",
",",
"$",
"range",
"->",
"end",
"->",
"character",
")",
")",
")",
";",
"}"
] | Returns the location of the node
@param Node $node
@return self | [
"Returns",
"the",
"location",
"of",
"the",
"node"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Factory/LocationFactory.php#L19-L31 | train |
felixfbecker/php-language-server | src/Client/Workspace.php | Workspace.xfiles | public function xfiles(string $base = null): Promise
{
return $this->handler->request(
'workspace/xfiles',
['base' => $base]
)->then(function (array $textDocuments) {
return $this->mapper->mapArray($textDocuments, [], TextDocumentIdentifier::class);
});
} | php | public function xfiles(string $base = null): Promise
{
return $this->handler->request(
'workspace/xfiles',
['base' => $base]
)->then(function (array $textDocuments) {
return $this->mapper->mapArray($textDocuments, [], TextDocumentIdentifier::class);
});
} | [
"public",
"function",
"xfiles",
"(",
"string",
"$",
"base",
"=",
"null",
")",
":",
"Promise",
"{",
"return",
"$",
"this",
"->",
"handler",
"->",
"request",
"(",
"'workspace/xfiles'",
",",
"[",
"'base'",
"=>",
"$",
"base",
"]",
")",
"->",
"then",
"(",
"function",
"(",
"array",
"$",
"textDocuments",
")",
"{",
"return",
"$",
"this",
"->",
"mapper",
"->",
"mapArray",
"(",
"$",
"textDocuments",
",",
"[",
"]",
",",
"TextDocumentIdentifier",
"::",
"class",
")",
";",
"}",
")",
";",
"}"
] | Returns a list of all files in a directory
@param string $base The base directory (defaults to the workspace)
@return Promise <TextDocumentIdentifier[]> Array of documents | [
"Returns",
"a",
"list",
"of",
"all",
"files",
"in",
"a",
"directory"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Client/Workspace.php#L38-L46 | train |
felixfbecker/php-language-server | src/Server/TextDocument.php | TextDocument.documentSymbol | public function documentSymbol(TextDocumentIdentifier $textDocument): Promise
{
return $this->documentLoader->getOrLoad($textDocument->uri)->then(function (PhpDocument $document) {
$symbols = [];
foreach ($document->getDefinitions() as $fqn => $definition) {
$symbols[] = $definition->symbolInformation;
}
return $symbols;
});
} | php | public function documentSymbol(TextDocumentIdentifier $textDocument): Promise
{
return $this->documentLoader->getOrLoad($textDocument->uri)->then(function (PhpDocument $document) {
$symbols = [];
foreach ($document->getDefinitions() as $fqn => $definition) {
$symbols[] = $definition->symbolInformation;
}
return $symbols;
});
} | [
"public",
"function",
"documentSymbol",
"(",
"TextDocumentIdentifier",
"$",
"textDocument",
")",
":",
"Promise",
"{",
"return",
"$",
"this",
"->",
"documentLoader",
"->",
"getOrLoad",
"(",
"$",
"textDocument",
"->",
"uri",
")",
"->",
"then",
"(",
"function",
"(",
"PhpDocument",
"$",
"document",
")",
"{",
"$",
"symbols",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"document",
"->",
"getDefinitions",
"(",
")",
"as",
"$",
"fqn",
"=>",
"$",
"definition",
")",
"{",
"$",
"symbols",
"[",
"]",
"=",
"$",
"definition",
"->",
"symbolInformation",
";",
"}",
"return",
"$",
"symbols",
";",
"}",
")",
";",
"}"
] | The document symbol request is sent from the client to the server to list all symbols found in a given text
document.
@param \LanguageServerProtocol\TextDocumentIdentifier $textDocument
@return Promise <SymbolInformation[]> | [
"The",
"document",
"symbol",
"request",
"is",
"sent",
"from",
"the",
"client",
"to",
"the",
"server",
"to",
"list",
"all",
"symbols",
"found",
"in",
"a",
"given",
"text",
"document",
"."
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Server/TextDocument.php#L116-L125 | train |
felixfbecker/php-language-server | src/Server/TextDocument.php | TextDocument.references | public function references(
ReferenceContext $context,
TextDocumentIdentifier $textDocument,
Position $position
): Promise {
return coroutine(function () use ($textDocument, $position) {
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
$node = $document->getNodeAtPosition($position);
if ($node === null) {
return [];
}
$locations = [];
// Variables always stay in the boundary of the file and need to be searched inside their function scope
// by traversing the AST
if (
($node instanceof Node\Expression\Variable && !($node->getParent()->getParent() instanceof Node\PropertyDeclaration))
|| $node instanceof Node\Parameter
|| $node instanceof Node\UseVariableName
) {
if (isset($node->name) && $node->name instanceof Node\Expression) {
return null;
}
// Find function/method/closure scope
$n = $node;
$n = $n->getFirstAncestor(Node\Statement\FunctionDeclaration::class, Node\MethodDeclaration::class, Node\Expression\AnonymousFunctionCreationExpression::class, Node\SourceFileNode::class);
if ($n === null) {
$n = $node->getFirstAncestor(Node\Statement\ExpressionStatement::class)->getParent();
}
foreach ($n->getDescendantNodes() as $descendantNode) {
if ($descendantNode instanceof Node\Expression\Variable &&
$descendantNode->getName() === $node->getName()
) {
$locations[] = LocationFactory::fromNode($descendantNode);
}
}
} else {
// Definition with a global FQN
$fqn = DefinitionResolver::getDefinedFqn($node);
// Wait until indexing finished
if (!$this->index->isComplete()) {
yield waitForEvent($this->index, 'complete');
}
if ($fqn === null) {
$fqn = $this->definitionResolver->resolveReferenceNodeToFqn($node);
if ($fqn === null) {
return [];
}
}
$refDocumentPromises = [];
foreach ($this->index->getReferenceUris($fqn) as $uri) {
$refDocumentPromises[] = $this->documentLoader->getOrLoad($uri);
}
$refDocuments = yield Promise\all($refDocumentPromises);
foreach ($refDocuments as $document) {
$refs = $document->getReferenceNodesByFqn($fqn);
if ($refs !== null) {
foreach ($refs as $ref) {
$locations[] = LocationFactory::fromNode($ref);
}
}
}
}
return $locations;
});
} | php | public function references(
ReferenceContext $context,
TextDocumentIdentifier $textDocument,
Position $position
): Promise {
return coroutine(function () use ($textDocument, $position) {
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
$node = $document->getNodeAtPosition($position);
if ($node === null) {
return [];
}
$locations = [];
// Variables always stay in the boundary of the file and need to be searched inside their function scope
// by traversing the AST
if (
($node instanceof Node\Expression\Variable && !($node->getParent()->getParent() instanceof Node\PropertyDeclaration))
|| $node instanceof Node\Parameter
|| $node instanceof Node\UseVariableName
) {
if (isset($node->name) && $node->name instanceof Node\Expression) {
return null;
}
// Find function/method/closure scope
$n = $node;
$n = $n->getFirstAncestor(Node\Statement\FunctionDeclaration::class, Node\MethodDeclaration::class, Node\Expression\AnonymousFunctionCreationExpression::class, Node\SourceFileNode::class);
if ($n === null) {
$n = $node->getFirstAncestor(Node\Statement\ExpressionStatement::class)->getParent();
}
foreach ($n->getDescendantNodes() as $descendantNode) {
if ($descendantNode instanceof Node\Expression\Variable &&
$descendantNode->getName() === $node->getName()
) {
$locations[] = LocationFactory::fromNode($descendantNode);
}
}
} else {
// Definition with a global FQN
$fqn = DefinitionResolver::getDefinedFqn($node);
// Wait until indexing finished
if (!$this->index->isComplete()) {
yield waitForEvent($this->index, 'complete');
}
if ($fqn === null) {
$fqn = $this->definitionResolver->resolveReferenceNodeToFqn($node);
if ($fqn === null) {
return [];
}
}
$refDocumentPromises = [];
foreach ($this->index->getReferenceUris($fqn) as $uri) {
$refDocumentPromises[] = $this->documentLoader->getOrLoad($uri);
}
$refDocuments = yield Promise\all($refDocumentPromises);
foreach ($refDocuments as $document) {
$refs = $document->getReferenceNodesByFqn($fqn);
if ($refs !== null) {
foreach ($refs as $ref) {
$locations[] = LocationFactory::fromNode($ref);
}
}
}
}
return $locations;
});
} | [
"public",
"function",
"references",
"(",
"ReferenceContext",
"$",
"context",
",",
"TextDocumentIdentifier",
"$",
"textDocument",
",",
"Position",
"$",
"position",
")",
":",
"Promise",
"{",
"return",
"coroutine",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"textDocument",
",",
"$",
"position",
")",
"{",
"$",
"document",
"=",
"yield",
"$",
"this",
"->",
"documentLoader",
"->",
"getOrLoad",
"(",
"$",
"textDocument",
"->",
"uri",
")",
";",
"$",
"node",
"=",
"$",
"document",
"->",
"getNodeAtPosition",
"(",
"$",
"position",
")",
";",
"if",
"(",
"$",
"node",
"===",
"null",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"locations",
"=",
"[",
"]",
";",
"// Variables always stay in the boundary of the file and need to be searched inside their function scope",
"// by traversing the AST",
"if",
"(",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"Variable",
"&&",
"!",
"(",
"$",
"node",
"->",
"getParent",
"(",
")",
"->",
"getParent",
"(",
")",
"instanceof",
"Node",
"\\",
"PropertyDeclaration",
")",
")",
"||",
"$",
"node",
"instanceof",
"Node",
"\\",
"Parameter",
"||",
"$",
"node",
"instanceof",
"Node",
"\\",
"UseVariableName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"node",
"->",
"name",
")",
"&&",
"$",
"node",
"->",
"name",
"instanceof",
"Node",
"\\",
"Expression",
")",
"{",
"return",
"null",
";",
"}",
"// Find function/method/closure scope",
"$",
"n",
"=",
"$",
"node",
";",
"$",
"n",
"=",
"$",
"n",
"->",
"getFirstAncestor",
"(",
"Node",
"\\",
"Statement",
"\\",
"FunctionDeclaration",
"::",
"class",
",",
"Node",
"\\",
"MethodDeclaration",
"::",
"class",
",",
"Node",
"\\",
"Expression",
"\\",
"AnonymousFunctionCreationExpression",
"::",
"class",
",",
"Node",
"\\",
"SourceFileNode",
"::",
"class",
")",
";",
"if",
"(",
"$",
"n",
"===",
"null",
")",
"{",
"$",
"n",
"=",
"$",
"node",
"->",
"getFirstAncestor",
"(",
"Node",
"\\",
"Statement",
"\\",
"ExpressionStatement",
"::",
"class",
")",
"->",
"getParent",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"n",
"->",
"getDescendantNodes",
"(",
")",
"as",
"$",
"descendantNode",
")",
"{",
"if",
"(",
"$",
"descendantNode",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"Variable",
"&&",
"$",
"descendantNode",
"->",
"getName",
"(",
")",
"===",
"$",
"node",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"locations",
"[",
"]",
"=",
"LocationFactory",
"::",
"fromNode",
"(",
"$",
"descendantNode",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// Definition with a global FQN",
"$",
"fqn",
"=",
"DefinitionResolver",
"::",
"getDefinedFqn",
"(",
"$",
"node",
")",
";",
"// Wait until indexing finished",
"if",
"(",
"!",
"$",
"this",
"->",
"index",
"->",
"isComplete",
"(",
")",
")",
"{",
"yield",
"waitForEvent",
"(",
"$",
"this",
"->",
"index",
",",
"'complete'",
")",
";",
"}",
"if",
"(",
"$",
"fqn",
"===",
"null",
")",
"{",
"$",
"fqn",
"=",
"$",
"this",
"->",
"definitionResolver",
"->",
"resolveReferenceNodeToFqn",
"(",
"$",
"node",
")",
";",
"if",
"(",
"$",
"fqn",
"===",
"null",
")",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"$",
"refDocumentPromises",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"index",
"->",
"getReferenceUris",
"(",
"$",
"fqn",
")",
"as",
"$",
"uri",
")",
"{",
"$",
"refDocumentPromises",
"[",
"]",
"=",
"$",
"this",
"->",
"documentLoader",
"->",
"getOrLoad",
"(",
"$",
"uri",
")",
";",
"}",
"$",
"refDocuments",
"=",
"yield",
"Promise",
"\\",
"all",
"(",
"$",
"refDocumentPromises",
")",
";",
"foreach",
"(",
"$",
"refDocuments",
"as",
"$",
"document",
")",
"{",
"$",
"refs",
"=",
"$",
"document",
"->",
"getReferenceNodesByFqn",
"(",
"$",
"fqn",
")",
";",
"if",
"(",
"$",
"refs",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"refs",
"as",
"$",
"ref",
")",
"{",
"$",
"locations",
"[",
"]",
"=",
"LocationFactory",
"::",
"fromNode",
"(",
"$",
"ref",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"locations",
";",
"}",
")",
";",
"}"
] | The references request is sent from the client to the server to resolve project-wide references for the symbol
denoted by the given text document position.
@param ReferenceContext $context
@return Promise <Location[]> | [
"The",
"references",
"request",
"is",
"sent",
"from",
"the",
"client",
"to",
"the",
"server",
"to",
"resolve",
"project",
"-",
"wide",
"references",
"for",
"the",
"symbol",
"denoted",
"by",
"the",
"given",
"text",
"document",
"position",
"."
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Server/TextDocument.php#L177-L246 | train |
felixfbecker/php-language-server | src/Server/TextDocument.php | TextDocument.signatureHelp | public function signatureHelp(TextDocumentIdentifier $textDocument, Position $position): Promise
{
return coroutine(function () use ($textDocument, $position) {
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
return $this->signatureHelpProvider->getSignatureHelp($document, $position);
});
} | php | public function signatureHelp(TextDocumentIdentifier $textDocument, Position $position): Promise
{
return coroutine(function () use ($textDocument, $position) {
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
return $this->signatureHelpProvider->getSignatureHelp($document, $position);
});
} | [
"public",
"function",
"signatureHelp",
"(",
"TextDocumentIdentifier",
"$",
"textDocument",
",",
"Position",
"$",
"position",
")",
":",
"Promise",
"{",
"return",
"coroutine",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"textDocument",
",",
"$",
"position",
")",
"{",
"$",
"document",
"=",
"yield",
"$",
"this",
"->",
"documentLoader",
"->",
"getOrLoad",
"(",
"$",
"textDocument",
"->",
"uri",
")",
";",
"return",
"$",
"this",
"->",
"signatureHelpProvider",
"->",
"getSignatureHelp",
"(",
"$",
"document",
",",
"$",
"position",
")",
";",
"}",
")",
";",
"}"
] | The signature help request is sent from the client to the server to request signature information at a given
cursor position.
@param TextDocumentIdentifier $textDocument The text document
@param Position $position The position inside the text document
@return Promise <SignatureHelp> | [
"The",
"signature",
"help",
"request",
"is",
"sent",
"from",
"the",
"client",
"to",
"the",
"server",
"to",
"request",
"signature",
"information",
"at",
"a",
"given",
"cursor",
"position",
"."
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Server/TextDocument.php#L257-L263 | train |
felixfbecker/php-language-server | src/Server/Workspace.php | Workspace.symbol | public function symbol(string $query): Promise
{
return coroutine(function () use ($query) {
// Wait until indexing for definitions finished
if (!$this->sourceIndex->isStaticComplete()) {
yield waitForEvent($this->sourceIndex, 'static-complete');
}
$symbols = [];
foreach ($this->sourceIndex->getDefinitions() as $fqn => $definition) {
if ($query === '' || stripos($fqn, $query) !== false) {
$symbols[] = $definition->symbolInformation;
}
}
return $symbols;
});
} | php | public function symbol(string $query): Promise
{
return coroutine(function () use ($query) {
// Wait until indexing for definitions finished
if (!$this->sourceIndex->isStaticComplete()) {
yield waitForEvent($this->sourceIndex, 'static-complete');
}
$symbols = [];
foreach ($this->sourceIndex->getDefinitions() as $fqn => $definition) {
if ($query === '' || stripos($fqn, $query) !== false) {
$symbols[] = $definition->symbolInformation;
}
}
return $symbols;
});
} | [
"public",
"function",
"symbol",
"(",
"string",
"$",
"query",
")",
":",
"Promise",
"{",
"return",
"coroutine",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"query",
")",
"{",
"// Wait until indexing for definitions finished",
"if",
"(",
"!",
"$",
"this",
"->",
"sourceIndex",
"->",
"isStaticComplete",
"(",
")",
")",
"{",
"yield",
"waitForEvent",
"(",
"$",
"this",
"->",
"sourceIndex",
",",
"'static-complete'",
")",
";",
"}",
"$",
"symbols",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"sourceIndex",
"->",
"getDefinitions",
"(",
")",
"as",
"$",
"fqn",
"=>",
"$",
"definition",
")",
"{",
"if",
"(",
"$",
"query",
"===",
"''",
"||",
"stripos",
"(",
"$",
"fqn",
",",
"$",
"query",
")",
"!==",
"false",
")",
"{",
"$",
"symbols",
"[",
"]",
"=",
"$",
"definition",
"->",
"symbolInformation",
";",
"}",
"}",
"return",
"$",
"symbols",
";",
"}",
")",
";",
"}"
] | The workspace symbol request is sent from the client to the server to list project-wide symbols matching the query string.
@param string $query
@return Promise <SymbolInformation[]> | [
"The",
"workspace",
"symbol",
"request",
"is",
"sent",
"from",
"the",
"client",
"to",
"the",
"server",
"to",
"list",
"project",
"-",
"wide",
"symbols",
"matching",
"the",
"query",
"string",
"."
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Server/Workspace.php#L84-L99 | train |
felixfbecker/php-language-server | src/Server/Workspace.php | Workspace.didChangeWatchedFiles | public function didChangeWatchedFiles(array $changes)
{
foreach ($changes as $change) {
if ($change->type === FileChangeType::DELETED) {
$this->client->textDocument->publishDiagnostics($change->uri, []);
}
}
} | php | public function didChangeWatchedFiles(array $changes)
{
foreach ($changes as $change) {
if ($change->type === FileChangeType::DELETED) {
$this->client->textDocument->publishDiagnostics($change->uri, []);
}
}
} | [
"public",
"function",
"didChangeWatchedFiles",
"(",
"array",
"$",
"changes",
")",
"{",
"foreach",
"(",
"$",
"changes",
"as",
"$",
"change",
")",
"{",
"if",
"(",
"$",
"change",
"->",
"type",
"===",
"FileChangeType",
"::",
"DELETED",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"textDocument",
"->",
"publishDiagnostics",
"(",
"$",
"change",
"->",
"uri",
",",
"[",
"]",
")",
";",
"}",
"}",
"}"
] | The watched files notification is sent from the client to the server when the client detects changes to files watched by the language client.
@param FileEvent[] $changes
@return void | [
"The",
"watched",
"files",
"notification",
"is",
"sent",
"from",
"the",
"client",
"to",
"the",
"server",
"when",
"the",
"client",
"detects",
"changes",
"to",
"files",
"watched",
"by",
"the",
"language",
"client",
"."
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Server/Workspace.php#L107-L114 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.getDeclarationLineFromNode | public function getDeclarationLineFromNode($node): string
{
// If node is part of a declaration list, build a declaration line that discludes other elements in the list
// - [PropertyDeclaration] // public $a, [$b = 3], $c; => public $b = 3;
// - [ConstDeclaration|ClassConstDeclaration] // "const A = 3, [B = 4];" => "const B = 4;"
if (
($declaration = ParserHelpers\tryGetPropertyDeclaration($node)) && ($elements = $declaration->propertyElements) ||
($declaration = ParserHelpers\tryGetConstOrClassConstDeclaration($node)) && ($elements = $declaration->constElements)
) {
$defLine = $declaration->getText();
$defLineStart = $declaration->getStart();
$defLine = \substr_replace(
$defLine,
$node->getFullText(),
$elements->getFullStart() - $defLineStart,
$elements->getFullWidth()
);
} else {
$defLine = $node->getText();
}
// Trim string to only include first line
$defLine = \rtrim(\strtok($defLine, "\n"), "\r");
// TODO - pretty print rather than getting text
return $defLine;
} | php | public function getDeclarationLineFromNode($node): string
{
// If node is part of a declaration list, build a declaration line that discludes other elements in the list
// - [PropertyDeclaration] // public $a, [$b = 3], $c; => public $b = 3;
// - [ConstDeclaration|ClassConstDeclaration] // "const A = 3, [B = 4];" => "const B = 4;"
if (
($declaration = ParserHelpers\tryGetPropertyDeclaration($node)) && ($elements = $declaration->propertyElements) ||
($declaration = ParserHelpers\tryGetConstOrClassConstDeclaration($node)) && ($elements = $declaration->constElements)
) {
$defLine = $declaration->getText();
$defLineStart = $declaration->getStart();
$defLine = \substr_replace(
$defLine,
$node->getFullText(),
$elements->getFullStart() - $defLineStart,
$elements->getFullWidth()
);
} else {
$defLine = $node->getText();
}
// Trim string to only include first line
$defLine = \rtrim(\strtok($defLine, "\n"), "\r");
// TODO - pretty print rather than getting text
return $defLine;
} | [
"public",
"function",
"getDeclarationLineFromNode",
"(",
"$",
"node",
")",
":",
"string",
"{",
"// If node is part of a declaration list, build a declaration line that discludes other elements in the list",
"// - [PropertyDeclaration] // public $a, [$b = 3], $c; => public $b = 3;",
"// - [ConstDeclaration|ClassConstDeclaration] // \"const A = 3, [B = 4];\" => \"const B = 4;\"",
"if",
"(",
"(",
"$",
"declaration",
"=",
"ParserHelpers",
"\\",
"tryGetPropertyDeclaration",
"(",
"$",
"node",
")",
")",
"&&",
"(",
"$",
"elements",
"=",
"$",
"declaration",
"->",
"propertyElements",
")",
"||",
"(",
"$",
"declaration",
"=",
"ParserHelpers",
"\\",
"tryGetConstOrClassConstDeclaration",
"(",
"$",
"node",
")",
")",
"&&",
"(",
"$",
"elements",
"=",
"$",
"declaration",
"->",
"constElements",
")",
")",
"{",
"$",
"defLine",
"=",
"$",
"declaration",
"->",
"getText",
"(",
")",
";",
"$",
"defLineStart",
"=",
"$",
"declaration",
"->",
"getStart",
"(",
")",
";",
"$",
"defLine",
"=",
"\\",
"substr_replace",
"(",
"$",
"defLine",
",",
"$",
"node",
"->",
"getFullText",
"(",
")",
",",
"$",
"elements",
"->",
"getFullStart",
"(",
")",
"-",
"$",
"defLineStart",
",",
"$",
"elements",
"->",
"getFullWidth",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"defLine",
"=",
"$",
"node",
"->",
"getText",
"(",
")",
";",
"}",
"// Trim string to only include first line",
"$",
"defLine",
"=",
"\\",
"rtrim",
"(",
"\\",
"strtok",
"(",
"$",
"defLine",
",",
"\"\\n\"",
")",
",",
"\"\\r\"",
")",
";",
"// TODO - pretty print rather than getting text",
"return",
"$",
"defLine",
";",
"}"
] | Builds the declaration line for a given node. Declarations with multiple lines are trimmed.
@param Node $node
@return string | [
"Builds",
"the",
"declaration",
"line",
"for",
"a",
"given",
"node",
".",
"Declarations",
"with",
"multiple",
"lines",
"are",
"trimmed",
"."
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L63-L91 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.getDocumentationFromNode | public function getDocumentationFromNode($node)
{
// Any NamespaceDefinition comments likely apply to the file, not the declaration itself.
if ($node instanceof Node\Statement\NamespaceDefinition) {
return null;
}
// For properties and constants, set the node to the declaration node, rather than the individual property.
// This is because they get defined as part of a list.
$constOrPropertyDeclaration = ParserHelpers\tryGetPropertyDeclaration($node) ?? ParserHelpers\tryGetConstOrClassConstDeclaration($node);
if ($constOrPropertyDeclaration !== null) {
$node = $constOrPropertyDeclaration;
}
// For parameters, parse the function-like declaration to get documentation for a parameter
if ($node instanceof Node\Parameter) {
$variableName = $node->getName();
$functionLikeDeclaration = ParserHelpers\getFunctionLikeDeclarationFromParameter($node);
$docBlock = $this->getDocBlock($functionLikeDeclaration);
$parameterDocBlockTag = $this->tryGetDocBlockTagForParameter($docBlock, $variableName);
return $parameterDocBlockTag !== null ? $parameterDocBlockTag->getDescription()->render() : null;
}
// For everything else, get the doc block summary corresponding to the current node.
$docBlock = $this->getDocBlock($node);
if ($docBlock !== null) {
// check whether we have a description, when true, add a new paragraph
// with the description
$description = $docBlock->getDescription()->render();
if (empty($description)) {
return $docBlock->getSummary();
}
return $docBlock->getSummary() . "\n\n" . $description;
}
return null;
} | php | public function getDocumentationFromNode($node)
{
// Any NamespaceDefinition comments likely apply to the file, not the declaration itself.
if ($node instanceof Node\Statement\NamespaceDefinition) {
return null;
}
// For properties and constants, set the node to the declaration node, rather than the individual property.
// This is because they get defined as part of a list.
$constOrPropertyDeclaration = ParserHelpers\tryGetPropertyDeclaration($node) ?? ParserHelpers\tryGetConstOrClassConstDeclaration($node);
if ($constOrPropertyDeclaration !== null) {
$node = $constOrPropertyDeclaration;
}
// For parameters, parse the function-like declaration to get documentation for a parameter
if ($node instanceof Node\Parameter) {
$variableName = $node->getName();
$functionLikeDeclaration = ParserHelpers\getFunctionLikeDeclarationFromParameter($node);
$docBlock = $this->getDocBlock($functionLikeDeclaration);
$parameterDocBlockTag = $this->tryGetDocBlockTagForParameter($docBlock, $variableName);
return $parameterDocBlockTag !== null ? $parameterDocBlockTag->getDescription()->render() : null;
}
// For everything else, get the doc block summary corresponding to the current node.
$docBlock = $this->getDocBlock($node);
if ($docBlock !== null) {
// check whether we have a description, when true, add a new paragraph
// with the description
$description = $docBlock->getDescription()->render();
if (empty($description)) {
return $docBlock->getSummary();
}
return $docBlock->getSummary() . "\n\n" . $description;
}
return null;
} | [
"public",
"function",
"getDocumentationFromNode",
"(",
"$",
"node",
")",
"{",
"// Any NamespaceDefinition comments likely apply to the file, not the declaration itself.",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"NamespaceDefinition",
")",
"{",
"return",
"null",
";",
"}",
"// For properties and constants, set the node to the declaration node, rather than the individual property.",
"// This is because they get defined as part of a list.",
"$",
"constOrPropertyDeclaration",
"=",
"ParserHelpers",
"\\",
"tryGetPropertyDeclaration",
"(",
"$",
"node",
")",
"??",
"ParserHelpers",
"\\",
"tryGetConstOrClassConstDeclaration",
"(",
"$",
"node",
")",
";",
"if",
"(",
"$",
"constOrPropertyDeclaration",
"!==",
"null",
")",
"{",
"$",
"node",
"=",
"$",
"constOrPropertyDeclaration",
";",
"}",
"// For parameters, parse the function-like declaration to get documentation for a parameter",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Parameter",
")",
"{",
"$",
"variableName",
"=",
"$",
"node",
"->",
"getName",
"(",
")",
";",
"$",
"functionLikeDeclaration",
"=",
"ParserHelpers",
"\\",
"getFunctionLikeDeclarationFromParameter",
"(",
"$",
"node",
")",
";",
"$",
"docBlock",
"=",
"$",
"this",
"->",
"getDocBlock",
"(",
"$",
"functionLikeDeclaration",
")",
";",
"$",
"parameterDocBlockTag",
"=",
"$",
"this",
"->",
"tryGetDocBlockTagForParameter",
"(",
"$",
"docBlock",
",",
"$",
"variableName",
")",
";",
"return",
"$",
"parameterDocBlockTag",
"!==",
"null",
"?",
"$",
"parameterDocBlockTag",
"->",
"getDescription",
"(",
")",
"->",
"render",
"(",
")",
":",
"null",
";",
"}",
"// For everything else, get the doc block summary corresponding to the current node.",
"$",
"docBlock",
"=",
"$",
"this",
"->",
"getDocBlock",
"(",
"$",
"node",
")",
";",
"if",
"(",
"$",
"docBlock",
"!==",
"null",
")",
"{",
"// check whether we have a description, when true, add a new paragraph",
"// with the description",
"$",
"description",
"=",
"$",
"docBlock",
"->",
"getDescription",
"(",
")",
"->",
"render",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"description",
")",
")",
"{",
"return",
"$",
"docBlock",
"->",
"getSummary",
"(",
")",
";",
"}",
"return",
"$",
"docBlock",
"->",
"getSummary",
"(",
")",
".",
"\"\\n\\n\"",
".",
"$",
"description",
";",
"}",
"return",
"null",
";",
"}"
] | Gets the documentation string for a node, if it has one
@param Node $node
@return string|null | [
"Gets",
"the",
"documentation",
"string",
"for",
"a",
"node",
"if",
"it",
"has",
"one"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L99-L138 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.getDocBlock | private function getDocBlock(Node $node)
{
// TODO make more efficient (caching, ensure import table is in right format to begin with)
$docCommentText = $node->getDocCommentText();
if ($docCommentText !== null) {
list($namespaceImportTable,,) = $node->getImportTablesForCurrentScope();
foreach ($namespaceImportTable as $alias => $name) {
$namespaceImportTable[$alias] = (string)$name;
}
$namespaceDefinition = $node->getNamespaceDefinition();
if ($namespaceDefinition !== null && $namespaceDefinition->name !== null) {
$namespaceName = (string)$namespaceDefinition->name->getNamespacedName();
} else {
$namespaceName = 'global';
}
$context = new Types\Context($namespaceName, $namespaceImportTable);
try {
// create() throws when it thinks the doc comment has invalid fields.
// For example, a @see tag that is followed by something that doesn't look like a valid fqsen will throw.
return $this->docBlockFactory->create($docCommentText, $context);
} catch (\InvalidArgumentException $e) {
return null;
}
}
return null;
} | php | private function getDocBlock(Node $node)
{
// TODO make more efficient (caching, ensure import table is in right format to begin with)
$docCommentText = $node->getDocCommentText();
if ($docCommentText !== null) {
list($namespaceImportTable,,) = $node->getImportTablesForCurrentScope();
foreach ($namespaceImportTable as $alias => $name) {
$namespaceImportTable[$alias] = (string)$name;
}
$namespaceDefinition = $node->getNamespaceDefinition();
if ($namespaceDefinition !== null && $namespaceDefinition->name !== null) {
$namespaceName = (string)$namespaceDefinition->name->getNamespacedName();
} else {
$namespaceName = 'global';
}
$context = new Types\Context($namespaceName, $namespaceImportTable);
try {
// create() throws when it thinks the doc comment has invalid fields.
// For example, a @see tag that is followed by something that doesn't look like a valid fqsen will throw.
return $this->docBlockFactory->create($docCommentText, $context);
} catch (\InvalidArgumentException $e) {
return null;
}
}
return null;
} | [
"private",
"function",
"getDocBlock",
"(",
"Node",
"$",
"node",
")",
"{",
"// TODO make more efficient (caching, ensure import table is in right format to begin with)",
"$",
"docCommentText",
"=",
"$",
"node",
"->",
"getDocCommentText",
"(",
")",
";",
"if",
"(",
"$",
"docCommentText",
"!==",
"null",
")",
"{",
"list",
"(",
"$",
"namespaceImportTable",
",",
",",
")",
"=",
"$",
"node",
"->",
"getImportTablesForCurrentScope",
"(",
")",
";",
"foreach",
"(",
"$",
"namespaceImportTable",
"as",
"$",
"alias",
"=>",
"$",
"name",
")",
"{",
"$",
"namespaceImportTable",
"[",
"$",
"alias",
"]",
"=",
"(",
"string",
")",
"$",
"name",
";",
"}",
"$",
"namespaceDefinition",
"=",
"$",
"node",
"->",
"getNamespaceDefinition",
"(",
")",
";",
"if",
"(",
"$",
"namespaceDefinition",
"!==",
"null",
"&&",
"$",
"namespaceDefinition",
"->",
"name",
"!==",
"null",
")",
"{",
"$",
"namespaceName",
"=",
"(",
"string",
")",
"$",
"namespaceDefinition",
"->",
"name",
"->",
"getNamespacedName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"namespaceName",
"=",
"'global'",
";",
"}",
"$",
"context",
"=",
"new",
"Types",
"\\",
"Context",
"(",
"$",
"namespaceName",
",",
"$",
"namespaceImportTable",
")",
";",
"try",
"{",
"// create() throws when it thinks the doc comment has invalid fields.",
"// For example, a @see tag that is followed by something that doesn't look like a valid fqsen will throw.",
"return",
"$",
"this",
"->",
"docBlockFactory",
"->",
"create",
"(",
"$",
"docCommentText",
",",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Gets Doc Block with resolved names for a Node
@param Node $node
@return DocBlock|null | [
"Gets",
"Doc",
"Block",
"with",
"resolved",
"names",
"for",
"a",
"Node"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L146-L172 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.createDefinitionFromNode | public function createDefinitionFromNode(Node $node, string $fqn = null): Definition
{
$def = new Definition;
$def->fqn = $fqn;
// Determines whether the suggestion will show after "new"
$def->canBeInstantiated = (
$node instanceof Node\Statement\ClassDeclaration &&
// check whether it is not an abstract class
($node->abstractOrFinalModifier === null || $node->abstractOrFinalModifier->kind !== PhpParser\TokenKind::AbstractKeyword)
);
// Interfaces, classes, traits, namespaces, functions, and global const elements
$def->isMember = !(
$node instanceof PhpParser\ClassLike ||
($node instanceof Node\Statement\NamespaceDefinition && $node->name !== null) ||
$node instanceof Node\Statement\FunctionDeclaration ||
($node instanceof Node\ConstElement && $node->parent->parent instanceof Node\Statement\ConstDeclaration)
);
// Definition is affected by global namespace fallback if it is a global constant or a global function
$def->roamed = (
$fqn !== null
&& strpos($fqn, '\\') === false
&& (
($node instanceof Node\ConstElement && $node->parent->parent instanceof Node\Statement\ConstDeclaration)
|| $node instanceof Node\Statement\FunctionDeclaration
)
);
// Static methods and static property declarations
$def->isStatic = (
($node instanceof Node\MethodDeclaration && $node->isStatic()) ||
(($propertyDeclaration = ParserHelpers\tryGetPropertyDeclaration($node)) !== null
&& $propertyDeclaration->isStatic())
);
if ($node instanceof Node\Statement\ClassDeclaration &&
// TODO - this should be better represented in the parser API
$node->classBaseClause !== null && $node->classBaseClause->baseClass !== null) {
$def->extends = [(string)$node->classBaseClause->baseClass->getResolvedName()];
} elseif (
$node instanceof Node\Statement\InterfaceDeclaration &&
// TODO - this should be better represented in the parser API
$node->interfaceBaseClause !== null && $node->interfaceBaseClause->interfaceNameList !== null
) {
$def->extends = [];
foreach ($node->interfaceBaseClause->interfaceNameList->getValues() as $n) {
$def->extends[] = (string)$n->getResolvedName();
}
}
$def->symbolInformation = SymbolInformationFactory::fromNode($node, $fqn);
if ($def->symbolInformation !== null) {
$def->type = $this->getTypeFromNode($node);
$def->declarationLine = $this->getDeclarationLineFromNode($node);
$def->documentation = $this->getDocumentationFromNode($node);
}
if ($node instanceof FunctionLike) {
$def->signatureInformation = $this->signatureInformationFactory->create($node);
}
return $def;
} | php | public function createDefinitionFromNode(Node $node, string $fqn = null): Definition
{
$def = new Definition;
$def->fqn = $fqn;
// Determines whether the suggestion will show after "new"
$def->canBeInstantiated = (
$node instanceof Node\Statement\ClassDeclaration &&
// check whether it is not an abstract class
($node->abstractOrFinalModifier === null || $node->abstractOrFinalModifier->kind !== PhpParser\TokenKind::AbstractKeyword)
);
// Interfaces, classes, traits, namespaces, functions, and global const elements
$def->isMember = !(
$node instanceof PhpParser\ClassLike ||
($node instanceof Node\Statement\NamespaceDefinition && $node->name !== null) ||
$node instanceof Node\Statement\FunctionDeclaration ||
($node instanceof Node\ConstElement && $node->parent->parent instanceof Node\Statement\ConstDeclaration)
);
// Definition is affected by global namespace fallback if it is a global constant or a global function
$def->roamed = (
$fqn !== null
&& strpos($fqn, '\\') === false
&& (
($node instanceof Node\ConstElement && $node->parent->parent instanceof Node\Statement\ConstDeclaration)
|| $node instanceof Node\Statement\FunctionDeclaration
)
);
// Static methods and static property declarations
$def->isStatic = (
($node instanceof Node\MethodDeclaration && $node->isStatic()) ||
(($propertyDeclaration = ParserHelpers\tryGetPropertyDeclaration($node)) !== null
&& $propertyDeclaration->isStatic())
);
if ($node instanceof Node\Statement\ClassDeclaration &&
// TODO - this should be better represented in the parser API
$node->classBaseClause !== null && $node->classBaseClause->baseClass !== null) {
$def->extends = [(string)$node->classBaseClause->baseClass->getResolvedName()];
} elseif (
$node instanceof Node\Statement\InterfaceDeclaration &&
// TODO - this should be better represented in the parser API
$node->interfaceBaseClause !== null && $node->interfaceBaseClause->interfaceNameList !== null
) {
$def->extends = [];
foreach ($node->interfaceBaseClause->interfaceNameList->getValues() as $n) {
$def->extends[] = (string)$n->getResolvedName();
}
}
$def->symbolInformation = SymbolInformationFactory::fromNode($node, $fqn);
if ($def->symbolInformation !== null) {
$def->type = $this->getTypeFromNode($node);
$def->declarationLine = $this->getDeclarationLineFromNode($node);
$def->documentation = $this->getDocumentationFromNode($node);
}
if ($node instanceof FunctionLike) {
$def->signatureInformation = $this->signatureInformationFactory->create($node);
}
return $def;
} | [
"public",
"function",
"createDefinitionFromNode",
"(",
"Node",
"$",
"node",
",",
"string",
"$",
"fqn",
"=",
"null",
")",
":",
"Definition",
"{",
"$",
"def",
"=",
"new",
"Definition",
";",
"$",
"def",
"->",
"fqn",
"=",
"$",
"fqn",
";",
"// Determines whether the suggestion will show after \"new\"",
"$",
"def",
"->",
"canBeInstantiated",
"=",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"ClassDeclaration",
"&&",
"// check whether it is not an abstract class",
"(",
"$",
"node",
"->",
"abstractOrFinalModifier",
"===",
"null",
"||",
"$",
"node",
"->",
"abstractOrFinalModifier",
"->",
"kind",
"!==",
"PhpParser",
"\\",
"TokenKind",
"::",
"AbstractKeyword",
")",
")",
";",
"// Interfaces, classes, traits, namespaces, functions, and global const elements",
"$",
"def",
"->",
"isMember",
"=",
"!",
"(",
"$",
"node",
"instanceof",
"PhpParser",
"\\",
"ClassLike",
"||",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"NamespaceDefinition",
"&&",
"$",
"node",
"->",
"name",
"!==",
"null",
")",
"||",
"$",
"node",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"FunctionDeclaration",
"||",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"ConstElement",
"&&",
"$",
"node",
"->",
"parent",
"->",
"parent",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"ConstDeclaration",
")",
")",
";",
"// Definition is affected by global namespace fallback if it is a global constant or a global function",
"$",
"def",
"->",
"roamed",
"=",
"(",
"$",
"fqn",
"!==",
"null",
"&&",
"strpos",
"(",
"$",
"fqn",
",",
"'\\\\'",
")",
"===",
"false",
"&&",
"(",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"ConstElement",
"&&",
"$",
"node",
"->",
"parent",
"->",
"parent",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"ConstDeclaration",
")",
"||",
"$",
"node",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"FunctionDeclaration",
")",
")",
";",
"// Static methods and static property declarations",
"$",
"def",
"->",
"isStatic",
"=",
"(",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"MethodDeclaration",
"&&",
"$",
"node",
"->",
"isStatic",
"(",
")",
")",
"||",
"(",
"(",
"$",
"propertyDeclaration",
"=",
"ParserHelpers",
"\\",
"tryGetPropertyDeclaration",
"(",
"$",
"node",
")",
")",
"!==",
"null",
"&&",
"$",
"propertyDeclaration",
"->",
"isStatic",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"ClassDeclaration",
"&&",
"// TODO - this should be better represented in the parser API",
"$",
"node",
"->",
"classBaseClause",
"!==",
"null",
"&&",
"$",
"node",
"->",
"classBaseClause",
"->",
"baseClass",
"!==",
"null",
")",
"{",
"$",
"def",
"->",
"extends",
"=",
"[",
"(",
"string",
")",
"$",
"node",
"->",
"classBaseClause",
"->",
"baseClass",
"->",
"getResolvedName",
"(",
")",
"]",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Statement",
"\\",
"InterfaceDeclaration",
"&&",
"// TODO - this should be better represented in the parser API",
"$",
"node",
"->",
"interfaceBaseClause",
"!==",
"null",
"&&",
"$",
"node",
"->",
"interfaceBaseClause",
"->",
"interfaceNameList",
"!==",
"null",
")",
"{",
"$",
"def",
"->",
"extends",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"node",
"->",
"interfaceBaseClause",
"->",
"interfaceNameList",
"->",
"getValues",
"(",
")",
"as",
"$",
"n",
")",
"{",
"$",
"def",
"->",
"extends",
"[",
"]",
"=",
"(",
"string",
")",
"$",
"n",
"->",
"getResolvedName",
"(",
")",
";",
"}",
"}",
"$",
"def",
"->",
"symbolInformation",
"=",
"SymbolInformationFactory",
"::",
"fromNode",
"(",
"$",
"node",
",",
"$",
"fqn",
")",
";",
"if",
"(",
"$",
"def",
"->",
"symbolInformation",
"!==",
"null",
")",
"{",
"$",
"def",
"->",
"type",
"=",
"$",
"this",
"->",
"getTypeFromNode",
"(",
"$",
"node",
")",
";",
"$",
"def",
"->",
"declarationLine",
"=",
"$",
"this",
"->",
"getDeclarationLineFromNode",
"(",
"$",
"node",
")",
";",
"$",
"def",
"->",
"documentation",
"=",
"$",
"this",
"->",
"getDocumentationFromNode",
"(",
"$",
"node",
")",
";",
"}",
"if",
"(",
"$",
"node",
"instanceof",
"FunctionLike",
")",
"{",
"$",
"def",
"->",
"signatureInformation",
"=",
"$",
"this",
"->",
"signatureInformationFactory",
"->",
"create",
"(",
"$",
"node",
")",
";",
"}",
"return",
"$",
"def",
";",
"}"
] | Create a Definition for a definition node
@param Node $node
@param string $fqn
@return Definition | [
"Create",
"a",
"Definition",
"for",
"a",
"definition",
"node"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L181-L250 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.resolveReferenceNodeToDefinition | public function resolveReferenceNodeToDefinition(Node $node)
{
$parent = $node->parent;
// Variables are not indexed globally, as they stay in the file scope anyway.
// Ignore variable nodes that are part of ScopedPropertyAccessExpression,
// as the scoped property access expression node is handled separately.
if ($node instanceof Node\Expression\Variable &&
!($parent instanceof Node\Expression\ScopedPropertyAccessExpression)) {
// Resolve $this to the containing class definition.
if ($node->getName() === 'this' && $fqn = $this->getContainingClassFqn($node)) {
return $this->index->getDefinition($fqn, false);
}
// Resolve the variable to a definition node (assignment, param or closure use)
$defNode = $this->resolveVariableToNode($node);
if ($defNode === null) {
return null;
}
return $this->createDefinitionFromNode($defNode);
}
// Other references are references to a global symbol that have an FQN
// Find out the FQN
$fqn = $this->resolveReferenceNodeToFqn($node);
if (!$fqn) {
return null;
}
if ($fqn === 'self' || $fqn === 'static') {
// Resolve self and static keywords to the containing class
// (This is not 100% correct for static but better than nothing)
$classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
if (!$classNode) {
return;
}
$fqn = (string)$classNode->getNamespacedName();
if (!$fqn) {
return;
}
} else if ($fqn === 'parent') {
// Resolve parent keyword to the base class FQN
$classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
if (!$classNode || !$classNode->classBaseClause || !$classNode->classBaseClause->baseClass) {
return;
}
$fqn = (string)$classNode->classBaseClause->baseClass->getResolvedName();
if (!$fqn) {
return;
}
}
// If the node is a function or constant, it could be namespaced, but PHP falls back to global
// http://php.net/manual/en/language.namespaces.fallback.php
// TODO - verify that this is not a method
$globalFallback = ParserHelpers\isConstantFetch($node) || $parent instanceof Node\Expression\CallExpression;
// Return the Definition object from the index index
return $this->index->getDefinition($fqn, $globalFallback);
} | php | public function resolveReferenceNodeToDefinition(Node $node)
{
$parent = $node->parent;
// Variables are not indexed globally, as they stay in the file scope anyway.
// Ignore variable nodes that are part of ScopedPropertyAccessExpression,
// as the scoped property access expression node is handled separately.
if ($node instanceof Node\Expression\Variable &&
!($parent instanceof Node\Expression\ScopedPropertyAccessExpression)) {
// Resolve $this to the containing class definition.
if ($node->getName() === 'this' && $fqn = $this->getContainingClassFqn($node)) {
return $this->index->getDefinition($fqn, false);
}
// Resolve the variable to a definition node (assignment, param or closure use)
$defNode = $this->resolveVariableToNode($node);
if ($defNode === null) {
return null;
}
return $this->createDefinitionFromNode($defNode);
}
// Other references are references to a global symbol that have an FQN
// Find out the FQN
$fqn = $this->resolveReferenceNodeToFqn($node);
if (!$fqn) {
return null;
}
if ($fqn === 'self' || $fqn === 'static') {
// Resolve self and static keywords to the containing class
// (This is not 100% correct for static but better than nothing)
$classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
if (!$classNode) {
return;
}
$fqn = (string)$classNode->getNamespacedName();
if (!$fqn) {
return;
}
} else if ($fqn === 'parent') {
// Resolve parent keyword to the base class FQN
$classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
if (!$classNode || !$classNode->classBaseClause || !$classNode->classBaseClause->baseClass) {
return;
}
$fqn = (string)$classNode->classBaseClause->baseClass->getResolvedName();
if (!$fqn) {
return;
}
}
// If the node is a function or constant, it could be namespaced, but PHP falls back to global
// http://php.net/manual/en/language.namespaces.fallback.php
// TODO - verify that this is not a method
$globalFallback = ParserHelpers\isConstantFetch($node) || $parent instanceof Node\Expression\CallExpression;
// Return the Definition object from the index index
return $this->index->getDefinition($fqn, $globalFallback);
} | [
"public",
"function",
"resolveReferenceNodeToDefinition",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"parent",
"=",
"$",
"node",
"->",
"parent",
";",
"// Variables are not indexed globally, as they stay in the file scope anyway.",
"// Ignore variable nodes that are part of ScopedPropertyAccessExpression,",
"// as the scoped property access expression node is handled separately.",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"Variable",
"&&",
"!",
"(",
"$",
"parent",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"ScopedPropertyAccessExpression",
")",
")",
"{",
"// Resolve $this to the containing class definition.",
"if",
"(",
"$",
"node",
"->",
"getName",
"(",
")",
"===",
"'this'",
"&&",
"$",
"fqn",
"=",
"$",
"this",
"->",
"getContainingClassFqn",
"(",
"$",
"node",
")",
")",
"{",
"return",
"$",
"this",
"->",
"index",
"->",
"getDefinition",
"(",
"$",
"fqn",
",",
"false",
")",
";",
"}",
"// Resolve the variable to a definition node (assignment, param or closure use)",
"$",
"defNode",
"=",
"$",
"this",
"->",
"resolveVariableToNode",
"(",
"$",
"node",
")",
";",
"if",
"(",
"$",
"defNode",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"createDefinitionFromNode",
"(",
"$",
"defNode",
")",
";",
"}",
"// Other references are references to a global symbol that have an FQN",
"// Find out the FQN",
"$",
"fqn",
"=",
"$",
"this",
"->",
"resolveReferenceNodeToFqn",
"(",
"$",
"node",
")",
";",
"if",
"(",
"!",
"$",
"fqn",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"fqn",
"===",
"'self'",
"||",
"$",
"fqn",
"===",
"'static'",
")",
"{",
"// Resolve self and static keywords to the containing class",
"// (This is not 100% correct for static but better than nothing)",
"$",
"classNode",
"=",
"$",
"node",
"->",
"getFirstAncestor",
"(",
"Node",
"\\",
"Statement",
"\\",
"ClassDeclaration",
"::",
"class",
")",
";",
"if",
"(",
"!",
"$",
"classNode",
")",
"{",
"return",
";",
"}",
"$",
"fqn",
"=",
"(",
"string",
")",
"$",
"classNode",
"->",
"getNamespacedName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"fqn",
")",
"{",
"return",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"fqn",
"===",
"'parent'",
")",
"{",
"// Resolve parent keyword to the base class FQN",
"$",
"classNode",
"=",
"$",
"node",
"->",
"getFirstAncestor",
"(",
"Node",
"\\",
"Statement",
"\\",
"ClassDeclaration",
"::",
"class",
")",
";",
"if",
"(",
"!",
"$",
"classNode",
"||",
"!",
"$",
"classNode",
"->",
"classBaseClause",
"||",
"!",
"$",
"classNode",
"->",
"classBaseClause",
"->",
"baseClass",
")",
"{",
"return",
";",
"}",
"$",
"fqn",
"=",
"(",
"string",
")",
"$",
"classNode",
"->",
"classBaseClause",
"->",
"baseClass",
"->",
"getResolvedName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"fqn",
")",
"{",
"return",
";",
"}",
"}",
"// If the node is a function or constant, it could be namespaced, but PHP falls back to global",
"// http://php.net/manual/en/language.namespaces.fallback.php",
"// TODO - verify that this is not a method",
"$",
"globalFallback",
"=",
"ParserHelpers",
"\\",
"isConstantFetch",
"(",
"$",
"node",
")",
"||",
"$",
"parent",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"CallExpression",
";",
"// Return the Definition object from the index index",
"return",
"$",
"this",
"->",
"index",
"->",
"getDefinition",
"(",
"$",
"fqn",
",",
"$",
"globalFallback",
")",
";",
"}"
] | Given any node, returns the Definition object of the symbol that is referenced
@param Node $node Any reference node
@return Definition|null | [
"Given",
"any",
"node",
"returns",
"the",
"Definition",
"object",
"of",
"the",
"symbol",
"that",
"is",
"referenced"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L258-L315 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.resolveReferenceNodeToFqn | public function resolveReferenceNodeToFqn(Node $node)
{
// TODO all name tokens should be a part of a node
if ($node instanceof Node\QualifiedName) {
return $this->resolveQualifiedNameNodeToFqn($node);
} else if ($node instanceof Node\Expression\MemberAccessExpression) {
return $this->resolveMemberAccessExpressionNodeToFqn($node);
} else if (ParserHelpers\isConstantFetch($node)) {
return (string)($node->getNamespacedName());
} else if (
// A\B::C - constant access expression
$node instanceof Node\Expression\ScopedPropertyAccessExpression
&& !($node->memberName instanceof Node\Expression\Variable)
) {
return $this->resolveScopedPropertyAccessExpressionNodeToFqn($node);
} else if (
// A\B::$c - static property access expression
$node->parent instanceof Node\Expression\ScopedPropertyAccessExpression
) {
return $this->resolveScopedPropertyAccessExpressionNodeToFqn($node->parent);
}
return null;
} | php | public function resolveReferenceNodeToFqn(Node $node)
{
// TODO all name tokens should be a part of a node
if ($node instanceof Node\QualifiedName) {
return $this->resolveQualifiedNameNodeToFqn($node);
} else if ($node instanceof Node\Expression\MemberAccessExpression) {
return $this->resolveMemberAccessExpressionNodeToFqn($node);
} else if (ParserHelpers\isConstantFetch($node)) {
return (string)($node->getNamespacedName());
} else if (
// A\B::C - constant access expression
$node instanceof Node\Expression\ScopedPropertyAccessExpression
&& !($node->memberName instanceof Node\Expression\Variable)
) {
return $this->resolveScopedPropertyAccessExpressionNodeToFqn($node);
} else if (
// A\B::$c - static property access expression
$node->parent instanceof Node\Expression\ScopedPropertyAccessExpression
) {
return $this->resolveScopedPropertyAccessExpressionNodeToFqn($node->parent);
}
return null;
} | [
"public",
"function",
"resolveReferenceNodeToFqn",
"(",
"Node",
"$",
"node",
")",
"{",
"// TODO all name tokens should be a part of a node",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"QualifiedName",
")",
"{",
"return",
"$",
"this",
"->",
"resolveQualifiedNameNodeToFqn",
"(",
"$",
"node",
")",
";",
"}",
"else",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"MemberAccessExpression",
")",
"{",
"return",
"$",
"this",
"->",
"resolveMemberAccessExpressionNodeToFqn",
"(",
"$",
"node",
")",
";",
"}",
"else",
"if",
"(",
"ParserHelpers",
"\\",
"isConstantFetch",
"(",
"$",
"node",
")",
")",
"{",
"return",
"(",
"string",
")",
"(",
"$",
"node",
"->",
"getNamespacedName",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"// A\\B::C - constant access expression",
"$",
"node",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"ScopedPropertyAccessExpression",
"&&",
"!",
"(",
"$",
"node",
"->",
"memberName",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"Variable",
")",
")",
"{",
"return",
"$",
"this",
"->",
"resolveScopedPropertyAccessExpressionNodeToFqn",
"(",
"$",
"node",
")",
";",
"}",
"else",
"if",
"(",
"// A\\B::$c - static property access expression",
"$",
"node",
"->",
"parent",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"ScopedPropertyAccessExpression",
")",
"{",
"return",
"$",
"this",
"->",
"resolveScopedPropertyAccessExpressionNodeToFqn",
"(",
"$",
"node",
"->",
"parent",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Given any node, returns the FQN of the symbol that is referenced
Returns null if the FQN could not be resolved or the reference node references a variable
May also return "static", "self" or "parent"
@param Node $node
@return string|null | [
"Given",
"any",
"node",
"returns",
"the",
"FQN",
"of",
"the",
"symbol",
"that",
"is",
"referenced",
"Returns",
"null",
"if",
"the",
"FQN",
"could",
"not",
"be",
"resolved",
"or",
"the",
"reference",
"node",
"references",
"a",
"variable",
"May",
"also",
"return",
"static",
"self",
"or",
"parent"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L325-L348 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.getContainingClassFqn | private static function getContainingClassFqn(Node $node)
{
$classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
if ($classNode === null) {
return null;
}
return (string)$classNode->getNamespacedName();
} | php | private static function getContainingClassFqn(Node $node)
{
$classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
if ($classNode === null) {
return null;
}
return (string)$classNode->getNamespacedName();
} | [
"private",
"static",
"function",
"getContainingClassFqn",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"classNode",
"=",
"$",
"node",
"->",
"getFirstAncestor",
"(",
"Node",
"\\",
"Statement",
"\\",
"ClassDeclaration",
"::",
"class",
")",
";",
"if",
"(",
"$",
"classNode",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"(",
"string",
")",
"$",
"classNode",
"->",
"getNamespacedName",
"(",
")",
";",
"}"
] | Returns FQN of the class a node is contained in
Returns null if the class is anonymous or the node is not contained in a class
@param Node $node
@return string|null | [
"Returns",
"FQN",
"of",
"the",
"class",
"a",
"node",
"is",
"contained",
"in",
"Returns",
"null",
"if",
"the",
"class",
"is",
"anonymous",
"or",
"the",
"node",
"is",
"not",
"contained",
"in",
"a",
"class"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L527-L534 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.getContainingClassType | private function getContainingClassType(Node $node)
{
$classFqn = $this->getContainingClassFqn($node);
return $classFqn ? new Types\Object_(new Fqsen('\\' . $classFqn)) : null;
} | php | private function getContainingClassType(Node $node)
{
$classFqn = $this->getContainingClassFqn($node);
return $classFqn ? new Types\Object_(new Fqsen('\\' . $classFqn)) : null;
} | [
"private",
"function",
"getContainingClassType",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"classFqn",
"=",
"$",
"this",
"->",
"getContainingClassFqn",
"(",
"$",
"node",
")",
";",
"return",
"$",
"classFqn",
"?",
"new",
"Types",
"\\",
"Object_",
"(",
"new",
"Fqsen",
"(",
"'\\\\'",
".",
"$",
"classFqn",
")",
")",
":",
"null",
";",
"}"
] | Returns the type of the class a node is contained in
Returns null if the class is anonymous or the node is not contained in a class
@param Node $node The node used to find the containing class
@return Types\Object_|null | [
"Returns",
"the",
"type",
"of",
"the",
"class",
"a",
"node",
"is",
"contained",
"in",
"Returns",
"null",
"if",
"the",
"class",
"is",
"anonymous",
"or",
"the",
"node",
"is",
"not",
"contained",
"in",
"a",
"class"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L544-L548 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.resolveVariableToNode | public function resolveVariableToNode($var)
{
$n = $var;
// When a use is passed, start outside the closure to not return immediately
// Use variable vs variable parsing?
if ($var instanceof Node\UseVariableName) {
$n = $var->getFirstAncestor(Node\Expression\AnonymousFunctionCreationExpression::class)->parent;
$name = $var->getName();
} else if ($var instanceof Node\Expression\Variable || $var instanceof Node\Parameter) {
$name = $var->getName();
} else {
throw new \InvalidArgumentException('$var must be Variable, Param or ClosureUse, not ' . get_class($var));
}
if (empty($name)) {
return null;
}
$shouldDescend = function ($nodeToDescand) {
// Make sure not to decend into functions or classes (they represent a scope boundary)
return !($nodeToDescand instanceof PhpParser\FunctionLike || $nodeToDescand instanceof PhpParser\ClassLike);
};
// Traverse the AST up
do {
// If a function is met, check the parameters and use statements
if ($n instanceof PhpParser\FunctionLike) {
if ($n->parameters !== null) {
foreach ($n->parameters->getElements() as $param) {
if ($param->getName() === $name) {
return $param;
}
}
}
// If it is a closure, also check use statements
if ($n instanceof Node\Expression\AnonymousFunctionCreationExpression &&
$n->anonymousFunctionUseClause !== null &&
$n->anonymousFunctionUseClause->useVariableNameList !== null) {
foreach ($n->anonymousFunctionUseClause->useVariableNameList->getElements() as $use) {
if ($use->getName() === $name) {
return $use;
}
}
}
break;
}
// Check each previous sibling node and their descendents for a variable assignment to that variable
// Each previous sibling could contain a declaration of the variable
while (($prevSibling = $n->getPreviousSibling()) !== null && $n = $prevSibling) {
// Check the sibling itself
if (self::isVariableDeclaration($n, $name)) {
return $n;
}
// Check descendant of this sibling (e.g. the children of a previous if block)
foreach ($n->getDescendantNodes($shouldDescend) as $descendant) {
if (self::isVariableDeclaration($descendant, $name)) {
return $descendant;
}
}
}
} while (isset($n) && $n = $n->parent);
// Return null if nothing was found
return null;
} | php | public function resolveVariableToNode($var)
{
$n = $var;
// When a use is passed, start outside the closure to not return immediately
// Use variable vs variable parsing?
if ($var instanceof Node\UseVariableName) {
$n = $var->getFirstAncestor(Node\Expression\AnonymousFunctionCreationExpression::class)->parent;
$name = $var->getName();
} else if ($var instanceof Node\Expression\Variable || $var instanceof Node\Parameter) {
$name = $var->getName();
} else {
throw new \InvalidArgumentException('$var must be Variable, Param or ClosureUse, not ' . get_class($var));
}
if (empty($name)) {
return null;
}
$shouldDescend = function ($nodeToDescand) {
// Make sure not to decend into functions or classes (they represent a scope boundary)
return !($nodeToDescand instanceof PhpParser\FunctionLike || $nodeToDescand instanceof PhpParser\ClassLike);
};
// Traverse the AST up
do {
// If a function is met, check the parameters and use statements
if ($n instanceof PhpParser\FunctionLike) {
if ($n->parameters !== null) {
foreach ($n->parameters->getElements() as $param) {
if ($param->getName() === $name) {
return $param;
}
}
}
// If it is a closure, also check use statements
if ($n instanceof Node\Expression\AnonymousFunctionCreationExpression &&
$n->anonymousFunctionUseClause !== null &&
$n->anonymousFunctionUseClause->useVariableNameList !== null) {
foreach ($n->anonymousFunctionUseClause->useVariableNameList->getElements() as $use) {
if ($use->getName() === $name) {
return $use;
}
}
}
break;
}
// Check each previous sibling node and their descendents for a variable assignment to that variable
// Each previous sibling could contain a declaration of the variable
while (($prevSibling = $n->getPreviousSibling()) !== null && $n = $prevSibling) {
// Check the sibling itself
if (self::isVariableDeclaration($n, $name)) {
return $n;
}
// Check descendant of this sibling (e.g. the children of a previous if block)
foreach ($n->getDescendantNodes($shouldDescend) as $descendant) {
if (self::isVariableDeclaration($descendant, $name)) {
return $descendant;
}
}
}
} while (isset($n) && $n = $n->parent);
// Return null if nothing was found
return null;
} | [
"public",
"function",
"resolveVariableToNode",
"(",
"$",
"var",
")",
"{",
"$",
"n",
"=",
"$",
"var",
";",
"// When a use is passed, start outside the closure to not return immediately",
"// Use variable vs variable parsing?",
"if",
"(",
"$",
"var",
"instanceof",
"Node",
"\\",
"UseVariableName",
")",
"{",
"$",
"n",
"=",
"$",
"var",
"->",
"getFirstAncestor",
"(",
"Node",
"\\",
"Expression",
"\\",
"AnonymousFunctionCreationExpression",
"::",
"class",
")",
"->",
"parent",
";",
"$",
"name",
"=",
"$",
"var",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
"var",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"Variable",
"||",
"$",
"var",
"instanceof",
"Node",
"\\",
"Parameter",
")",
"{",
"$",
"name",
"=",
"$",
"var",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$var must be Variable, Param or ClosureUse, not '",
".",
"get_class",
"(",
"$",
"var",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"shouldDescend",
"=",
"function",
"(",
"$",
"nodeToDescand",
")",
"{",
"// Make sure not to decend into functions or classes (they represent a scope boundary)",
"return",
"!",
"(",
"$",
"nodeToDescand",
"instanceof",
"PhpParser",
"\\",
"FunctionLike",
"||",
"$",
"nodeToDescand",
"instanceof",
"PhpParser",
"\\",
"ClassLike",
")",
";",
"}",
";",
"// Traverse the AST up",
"do",
"{",
"// If a function is met, check the parameters and use statements",
"if",
"(",
"$",
"n",
"instanceof",
"PhpParser",
"\\",
"FunctionLike",
")",
"{",
"if",
"(",
"$",
"n",
"->",
"parameters",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"n",
"->",
"parameters",
"->",
"getElements",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"param",
";",
"}",
"}",
"}",
"// If it is a closure, also check use statements",
"if",
"(",
"$",
"n",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"AnonymousFunctionCreationExpression",
"&&",
"$",
"n",
"->",
"anonymousFunctionUseClause",
"!==",
"null",
"&&",
"$",
"n",
"->",
"anonymousFunctionUseClause",
"->",
"useVariableNameList",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"n",
"->",
"anonymousFunctionUseClause",
"->",
"useVariableNameList",
"->",
"getElements",
"(",
")",
"as",
"$",
"use",
")",
"{",
"if",
"(",
"$",
"use",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"use",
";",
"}",
"}",
"}",
"break",
";",
"}",
"// Check each previous sibling node and their descendents for a variable assignment to that variable",
"// Each previous sibling could contain a declaration of the variable",
"while",
"(",
"(",
"$",
"prevSibling",
"=",
"$",
"n",
"->",
"getPreviousSibling",
"(",
")",
")",
"!==",
"null",
"&&",
"$",
"n",
"=",
"$",
"prevSibling",
")",
"{",
"// Check the sibling itself",
"if",
"(",
"self",
"::",
"isVariableDeclaration",
"(",
"$",
"n",
",",
"$",
"name",
")",
")",
"{",
"return",
"$",
"n",
";",
"}",
"// Check descendant of this sibling (e.g. the children of a previous if block)",
"foreach",
"(",
"$",
"n",
"->",
"getDescendantNodes",
"(",
"$",
"shouldDescend",
")",
"as",
"$",
"descendant",
")",
"{",
"if",
"(",
"self",
"::",
"isVariableDeclaration",
"(",
"$",
"descendant",
",",
"$",
"name",
")",
")",
"{",
"return",
"$",
"descendant",
";",
"}",
"}",
"}",
"}",
"while",
"(",
"isset",
"(",
"$",
"n",
")",
"&&",
"$",
"n",
"=",
"$",
"n",
"->",
"parent",
")",
";",
"// Return null if nothing was found",
"return",
"null",
";",
"}"
] | Returns the assignment or parameter node where a variable was defined
@param Node\Expression\Variable|Node\Expression\ClosureUse $var The variable access
@return Node\Expression\Assign|Node\Expression\AssignOp|Node\Param|Node\Expression\ClosureUse|null | [
"Returns",
"the",
"assignment",
"or",
"parameter",
"node",
"where",
"a",
"variable",
"was",
"defined"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L556-L621 | train |
felixfbecker/php-language-server | src/DefinitionResolver.php | DefinitionResolver.isVariableDeclaration | private static function isVariableDeclaration(Node $n, string $name)
{
if (
// TODO - clean this up
($n instanceof Node\Expression\AssignmentExpression && $n->operator->kind === PhpParser\TokenKind::EqualsToken)
&& $n->leftOperand instanceof Node\Expression\Variable && $n->leftOperand->getName() === $name
) {
return true;
}
if (
($n instanceof Node\ForeachValue || $n instanceof Node\ForeachKey)
&& $n->expression instanceof Node\Expression\Variable
&& $n->expression->getName() === $name
) {
return true;
}
return false;
} | php | private static function isVariableDeclaration(Node $n, string $name)
{
if (
// TODO - clean this up
($n instanceof Node\Expression\AssignmentExpression && $n->operator->kind === PhpParser\TokenKind::EqualsToken)
&& $n->leftOperand instanceof Node\Expression\Variable && $n->leftOperand->getName() === $name
) {
return true;
}
if (
($n instanceof Node\ForeachValue || $n instanceof Node\ForeachKey)
&& $n->expression instanceof Node\Expression\Variable
&& $n->expression->getName() === $name
) {
return true;
}
return false;
} | [
"private",
"static",
"function",
"isVariableDeclaration",
"(",
"Node",
"$",
"n",
",",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"// TODO - clean this up",
"(",
"$",
"n",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"AssignmentExpression",
"&&",
"$",
"n",
"->",
"operator",
"->",
"kind",
"===",
"PhpParser",
"\\",
"TokenKind",
"::",
"EqualsToken",
")",
"&&",
"$",
"n",
"->",
"leftOperand",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"Variable",
"&&",
"$",
"n",
"->",
"leftOperand",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"(",
"$",
"n",
"instanceof",
"Node",
"\\",
"ForeachValue",
"||",
"$",
"n",
"instanceof",
"Node",
"\\",
"ForeachKey",
")",
"&&",
"$",
"n",
"->",
"expression",
"instanceof",
"Node",
"\\",
"Expression",
"\\",
"Variable",
"&&",
"$",
"n",
"->",
"expression",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks whether the given Node declares the given variable name
@param Node $n The Node to check
@param string $name The name of the wanted variable
@return bool | [
"Checks",
"whether",
"the",
"given",
"Node",
"declares",
"the",
"given",
"variable",
"name"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/DefinitionResolver.php#L630-L649 | train |
felixfbecker/php-language-server | src/Index/Index.php | Index.setComplete | public function setComplete()
{
if (!$this->isStaticComplete()) {
$this->setStaticComplete();
}
$this->complete = true;
$this->emit('complete');
} | php | public function setComplete()
{
if (!$this->isStaticComplete()) {
$this->setStaticComplete();
}
$this->complete = true;
$this->emit('complete');
} | [
"public",
"function",
"setComplete",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isStaticComplete",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setStaticComplete",
"(",
")",
";",
"}",
"$",
"this",
"->",
"complete",
"=",
"true",
";",
"$",
"this",
"->",
"emit",
"(",
"'complete'",
")",
";",
"}"
] | Marks this index as complete
@return void | [
"Marks",
"this",
"index",
"as",
"complete"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Index/Index.php#L58-L65 | train |
felixfbecker/php-language-server | src/Index/Index.php | Index.getChildDefinitionsForFqn | public function getChildDefinitionsForFqn(string $fqn): \Generator
{
$parts = $this->splitFqn($fqn);
if ('' === end($parts)) {
// we want to return all the definitions in the given FQN, not only
// the one (non member) matching exactly the FQN.
array_pop($parts);
}
$result = $this->getIndexValue($parts, $this->definitions);
if (!$result) {
return;
}
foreach ($result as $name => $item) {
// Don't yield the parent
if ($name === '') {
continue;
}
if ($item instanceof Definition) {
yield $fqn.$name => $item;
} elseif (is_array($item) && isset($item[''])) {
yield $fqn.$name => $item[''];
}
}
} | php | public function getChildDefinitionsForFqn(string $fqn): \Generator
{
$parts = $this->splitFqn($fqn);
if ('' === end($parts)) {
// we want to return all the definitions in the given FQN, not only
// the one (non member) matching exactly the FQN.
array_pop($parts);
}
$result = $this->getIndexValue($parts, $this->definitions);
if (!$result) {
return;
}
foreach ($result as $name => $item) {
// Don't yield the parent
if ($name === '') {
continue;
}
if ($item instanceof Definition) {
yield $fqn.$name => $item;
} elseif (is_array($item) && isset($item[''])) {
yield $fqn.$name => $item[''];
}
}
} | [
"public",
"function",
"getChildDefinitionsForFqn",
"(",
"string",
"$",
"fqn",
")",
":",
"\\",
"Generator",
"{",
"$",
"parts",
"=",
"$",
"this",
"->",
"splitFqn",
"(",
"$",
"fqn",
")",
";",
"if",
"(",
"''",
"===",
"end",
"(",
"$",
"parts",
")",
")",
"{",
"// we want to return all the definitions in the given FQN, not only",
"// the one (non member) matching exactly the FQN.",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"getIndexValue",
"(",
"$",
"parts",
",",
"$",
"this",
"->",
"definitions",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"result",
"as",
"$",
"name",
"=>",
"$",
"item",
")",
"{",
"// Don't yield the parent",
"if",
"(",
"$",
"name",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"item",
"instanceof",
"Definition",
")",
"{",
"yield",
"$",
"fqn",
".",
"$",
"name",
"=>",
"$",
"item",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"item",
")",
"&&",
"isset",
"(",
"$",
"item",
"[",
"''",
"]",
")",
")",
"{",
"yield",
"$",
"fqn",
".",
"$",
"name",
"=>",
"$",
"item",
"[",
"''",
"]",
";",
"}",
"}",
"}"
] | Returns a Generator that yields all the direct child Definitions of a given FQN
@param string $fqn
@return \Generator yields Definition | [
"Returns",
"a",
"Generator",
"that",
"yields",
"all",
"the",
"direct",
"child",
"Definitions",
"of",
"a",
"given",
"FQN"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Index/Index.php#L115-L139 | train |
felixfbecker/php-language-server | src/Index/Index.php | Index.setDefinition | public function setDefinition(string $fqn, Definition $definition)
{
$parts = $this->splitFqn($fqn);
$this->indexDefinition(0, $parts, $this->definitions, $definition);
$this->emit('definition-added');
} | php | public function setDefinition(string $fqn, Definition $definition)
{
$parts = $this->splitFqn($fqn);
$this->indexDefinition(0, $parts, $this->definitions, $definition);
$this->emit('definition-added');
} | [
"public",
"function",
"setDefinition",
"(",
"string",
"$",
"fqn",
",",
"Definition",
"$",
"definition",
")",
"{",
"$",
"parts",
"=",
"$",
"this",
"->",
"splitFqn",
"(",
"$",
"fqn",
")",
";",
"$",
"this",
"->",
"indexDefinition",
"(",
"0",
",",
"$",
"parts",
",",
"$",
"this",
"->",
"definitions",
",",
"$",
"definition",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'definition-added'",
")",
";",
"}"
] | Registers a definition
@param string $fqn The fully qualified name of the symbol
@param Definition $definition The Definition object
@return void | [
"Registers",
"a",
"definition"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Index/Index.php#L172-L178 | train |
felixfbecker/php-language-server | src/Index/Index.php | Index.removeDefinition | public function removeDefinition(string $fqn)
{
$parts = $this->splitFqn($fqn);
$this->removeIndexedDefinition(0, $parts, $this->definitions, $this->definitions);
unset($this->references[$fqn]);
} | php | public function removeDefinition(string $fqn)
{
$parts = $this->splitFqn($fqn);
$this->removeIndexedDefinition(0, $parts, $this->definitions, $this->definitions);
unset($this->references[$fqn]);
} | [
"public",
"function",
"removeDefinition",
"(",
"string",
"$",
"fqn",
")",
"{",
"$",
"parts",
"=",
"$",
"this",
"->",
"splitFqn",
"(",
"$",
"fqn",
")",
";",
"$",
"this",
"->",
"removeIndexedDefinition",
"(",
"0",
",",
"$",
"parts",
",",
"$",
"this",
"->",
"definitions",
",",
"$",
"this",
"->",
"definitions",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"references",
"[",
"$",
"fqn",
"]",
")",
";",
"}"
] | Unsets the Definition for a specific symbol
and removes all references pointing to that symbol
@param string $fqn The fully qualified name of the symbol
@return void | [
"Unsets",
"the",
"Definition",
"for",
"a",
"specific",
"symbol",
"and",
"removes",
"all",
"references",
"pointing",
"to",
"that",
"symbol"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Index/Index.php#L187-L193 | train |
felixfbecker/php-language-server | src/Index/Index.php | Index.addReferenceUri | public function addReferenceUri(string $fqn, string $uri)
{
if (!isset($this->references[$fqn])) {
$this->references[$fqn] = [];
}
// TODO: use DS\Set instead of searching array
if (array_search($uri, $this->references[$fqn], true) === false) {
$this->references[$fqn][] = $uri;
}
} | php | public function addReferenceUri(string $fqn, string $uri)
{
if (!isset($this->references[$fqn])) {
$this->references[$fqn] = [];
}
// TODO: use DS\Set instead of searching array
if (array_search($uri, $this->references[$fqn], true) === false) {
$this->references[$fqn][] = $uri;
}
} | [
"public",
"function",
"addReferenceUri",
"(",
"string",
"$",
"fqn",
",",
"string",
"$",
"uri",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"references",
"[",
"$",
"fqn",
"]",
")",
")",
"{",
"$",
"this",
"->",
"references",
"[",
"$",
"fqn",
"]",
"=",
"[",
"]",
";",
"}",
"// TODO: use DS\\Set instead of searching array",
"if",
"(",
"array_search",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"references",
"[",
"$",
"fqn",
"]",
",",
"true",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"references",
"[",
"$",
"fqn",
"]",
"[",
"]",
"=",
"$",
"uri",
";",
"}",
"}"
] | Adds a document URI as a referencee of a specific symbol
@param string $fqn The fully qualified name of the symbol
@return void | [
"Adds",
"a",
"document",
"URI",
"as",
"a",
"referencee",
"of",
"a",
"specific",
"symbol"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Index/Index.php#L225-L234 | train |
felixfbecker/php-language-server | src/Index/Index.php | Index.removeReferenceUri | public function removeReferenceUri(string $fqn, string $uri)
{
if (!isset($this->references[$fqn])) {
return;
}
$index = array_search($fqn, $this->references[$fqn], true);
if ($index === false) {
return;
}
array_splice($this->references[$fqn], $index, 1);
} | php | public function removeReferenceUri(string $fqn, string $uri)
{
if (!isset($this->references[$fqn])) {
return;
}
$index = array_search($fqn, $this->references[$fqn], true);
if ($index === false) {
return;
}
array_splice($this->references[$fqn], $index, 1);
} | [
"public",
"function",
"removeReferenceUri",
"(",
"string",
"$",
"fqn",
",",
"string",
"$",
"uri",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"references",
"[",
"$",
"fqn",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"index",
"=",
"array_search",
"(",
"$",
"fqn",
",",
"$",
"this",
"->",
"references",
"[",
"$",
"fqn",
"]",
",",
"true",
")",
";",
"if",
"(",
"$",
"index",
"===",
"false",
")",
"{",
"return",
";",
"}",
"array_splice",
"(",
"$",
"this",
"->",
"references",
"[",
"$",
"fqn",
"]",
",",
"$",
"index",
",",
"1",
")",
";",
"}"
] | Removes a document URI as the container for a specific symbol
@param string $fqn The fully qualified name of the symbol
@param string $uri The URI
@return void | [
"Removes",
"a",
"document",
"URI",
"as",
"the",
"container",
"for",
"a",
"specific",
"symbol"
] | 9dc16565922ae1fcf18a69b15b3cd15152ea21e6 | https://github.com/felixfbecker/php-language-server/blob/9dc16565922ae1fcf18a69b15b3cd15152ea21e6/src/Index/Index.php#L243-L253 | train |
thephpleague/fractal | src/Scope.php | Scope.getIdentifier | public function getIdentifier($appendIdentifier = null)
{
$identifierParts = array_merge($this->parentScopes, [$this->scopeIdentifier, $appendIdentifier]);
return implode('.', array_filter($identifierParts));
} | php | public function getIdentifier($appendIdentifier = null)
{
$identifierParts = array_merge($this->parentScopes, [$this->scopeIdentifier, $appendIdentifier]);
return implode('.', array_filter($identifierParts));
} | [
"public",
"function",
"getIdentifier",
"(",
"$",
"appendIdentifier",
"=",
"null",
")",
"{",
"$",
"identifierParts",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"parentScopes",
",",
"[",
"$",
"this",
"->",
"scopeIdentifier",
",",
"$",
"appendIdentifier",
"]",
")",
";",
"return",
"implode",
"(",
"'.'",
",",
"array_filter",
"(",
"$",
"identifierParts",
")",
")",
";",
"}"
] | Get the unique identifier for this scope.
@param string $appendIdentifier
@return string | [
"Get",
"the",
"unique",
"identifier",
"for",
"this",
"scope",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Scope.php#L104-L109 | train |
thephpleague/fractal | src/Scope.php | Scope.toArray | public function toArray()
{
list($rawData, $rawIncludedData) = $this->executeResourceTransformers();
$serializer = $this->manager->getSerializer();
$data = $this->serializeResource($serializer, $rawData);
// If the serializer wants the includes to be side-loaded then we'll
// serialize the included data and merge it with the data.
if ($serializer->sideloadIncludes()) {
//Filter out any relation that wasn't requested
$rawIncludedData = array_map(array($this, 'filterFieldsets'), $rawIncludedData);
$includedData = $serializer->includedData($this->resource, $rawIncludedData);
// If the serializer wants to inject additional information
// about the included resources, it can do so now.
$data = $serializer->injectData($data, $rawIncludedData);
if ($this->isRootScope()) {
// If the serializer wants to have a final word about all
// the objects that are sideloaded, it can do so now.
$includedData = $serializer->filterIncludes(
$includedData,
$data
);
}
$data = $data + $includedData;
}
if ($this->resource instanceof Collection) {
if ($this->resource->hasCursor()) {
$pagination = $serializer->cursor($this->resource->getCursor());
} elseif ($this->resource->hasPaginator()) {
$pagination = $serializer->paginator($this->resource->getPaginator());
}
if (! empty($pagination)) {
$this->resource->setMetaValue(key($pagination), current($pagination));
}
}
// Pull out all of OUR metadata and any custom meta data to merge with the main level data
$meta = $serializer->meta($this->resource->getMeta());
// in case of returning NullResource we should return null and not to go with array_merge
if (is_null($data)) {
if (!empty($meta)) {
return $meta;
}
return null;
}
return $data + $meta;
} | php | public function toArray()
{
list($rawData, $rawIncludedData) = $this->executeResourceTransformers();
$serializer = $this->manager->getSerializer();
$data = $this->serializeResource($serializer, $rawData);
// If the serializer wants the includes to be side-loaded then we'll
// serialize the included data and merge it with the data.
if ($serializer->sideloadIncludes()) {
//Filter out any relation that wasn't requested
$rawIncludedData = array_map(array($this, 'filterFieldsets'), $rawIncludedData);
$includedData = $serializer->includedData($this->resource, $rawIncludedData);
// If the serializer wants to inject additional information
// about the included resources, it can do so now.
$data = $serializer->injectData($data, $rawIncludedData);
if ($this->isRootScope()) {
// If the serializer wants to have a final word about all
// the objects that are sideloaded, it can do so now.
$includedData = $serializer->filterIncludes(
$includedData,
$data
);
}
$data = $data + $includedData;
}
if ($this->resource instanceof Collection) {
if ($this->resource->hasCursor()) {
$pagination = $serializer->cursor($this->resource->getCursor());
} elseif ($this->resource->hasPaginator()) {
$pagination = $serializer->paginator($this->resource->getPaginator());
}
if (! empty($pagination)) {
$this->resource->setMetaValue(key($pagination), current($pagination));
}
}
// Pull out all of OUR metadata and any custom meta data to merge with the main level data
$meta = $serializer->meta($this->resource->getMeta());
// in case of returning NullResource we should return null and not to go with array_merge
if (is_null($data)) {
if (!empty($meta)) {
return $meta;
}
return null;
}
return $data + $meta;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"list",
"(",
"$",
"rawData",
",",
"$",
"rawIncludedData",
")",
"=",
"$",
"this",
"->",
"executeResourceTransformers",
"(",
")",
";",
"$",
"serializer",
"=",
"$",
"this",
"->",
"manager",
"->",
"getSerializer",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"serializeResource",
"(",
"$",
"serializer",
",",
"$",
"rawData",
")",
";",
"// If the serializer wants the includes to be side-loaded then we'll",
"// serialize the included data and merge it with the data.",
"if",
"(",
"$",
"serializer",
"->",
"sideloadIncludes",
"(",
")",
")",
"{",
"//Filter out any relation that wasn't requested",
"$",
"rawIncludedData",
"=",
"array_map",
"(",
"array",
"(",
"$",
"this",
",",
"'filterFieldsets'",
")",
",",
"$",
"rawIncludedData",
")",
";",
"$",
"includedData",
"=",
"$",
"serializer",
"->",
"includedData",
"(",
"$",
"this",
"->",
"resource",
",",
"$",
"rawIncludedData",
")",
";",
"// If the serializer wants to inject additional information",
"// about the included resources, it can do so now.",
"$",
"data",
"=",
"$",
"serializer",
"->",
"injectData",
"(",
"$",
"data",
",",
"$",
"rawIncludedData",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isRootScope",
"(",
")",
")",
"{",
"// If the serializer wants to have a final word about all",
"// the objects that are sideloaded, it can do so now.",
"$",
"includedData",
"=",
"$",
"serializer",
"->",
"filterIncludes",
"(",
"$",
"includedData",
",",
"$",
"data",
")",
";",
"}",
"$",
"data",
"=",
"$",
"data",
"+",
"$",
"includedData",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"resource",
"instanceof",
"Collection",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resource",
"->",
"hasCursor",
"(",
")",
")",
"{",
"$",
"pagination",
"=",
"$",
"serializer",
"->",
"cursor",
"(",
"$",
"this",
"->",
"resource",
"->",
"getCursor",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"resource",
"->",
"hasPaginator",
"(",
")",
")",
"{",
"$",
"pagination",
"=",
"$",
"serializer",
"->",
"paginator",
"(",
"$",
"this",
"->",
"resource",
"->",
"getPaginator",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"pagination",
")",
")",
"{",
"$",
"this",
"->",
"resource",
"->",
"setMetaValue",
"(",
"key",
"(",
"$",
"pagination",
")",
",",
"current",
"(",
"$",
"pagination",
")",
")",
";",
"}",
"}",
"// Pull out all of OUR metadata and any custom meta data to merge with the main level data",
"$",
"meta",
"=",
"$",
"serializer",
"->",
"meta",
"(",
"$",
"this",
"->",
"resource",
"->",
"getMeta",
"(",
")",
")",
";",
"// in case of returning NullResource we should return null and not to go with array_merge",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"meta",
")",
")",
"{",
"return",
"$",
"meta",
";",
"}",
"return",
"null",
";",
"}",
"return",
"$",
"data",
"+",
"$",
"meta",
";",
"}"
] | Convert the current data for this scope to an array.
@return array | [
"Convert",
"the",
"current",
"data",
"for",
"this",
"scope",
"to",
"an",
"array",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Scope.php#L233-L289 | train |
thephpleague/fractal | src/Scope.php | Scope.transformPrimitiveResource | public function transformPrimitiveResource()
{
if (! ($this->resource instanceof Primitive)) {
throw new InvalidArgumentException(
'Argument $resource should be an instance of League\Fractal\Resource\Primitive'
);
}
$transformer = $this->resource->getTransformer();
$data = $this->resource->getData();
if (null === $transformer) {
$transformedData = $data;
} elseif (is_callable($transformer)) {
$transformedData = call_user_func($transformer, $data);
} else {
$transformer->setCurrentScope($this);
$transformedData = $transformer->transform($data);
}
return $transformedData;
} | php | public function transformPrimitiveResource()
{
if (! ($this->resource instanceof Primitive)) {
throw new InvalidArgumentException(
'Argument $resource should be an instance of League\Fractal\Resource\Primitive'
);
}
$transformer = $this->resource->getTransformer();
$data = $this->resource->getData();
if (null === $transformer) {
$transformedData = $data;
} elseif (is_callable($transformer)) {
$transformedData = call_user_func($transformer, $data);
} else {
$transformer->setCurrentScope($this);
$transformedData = $transformer->transform($data);
}
return $transformedData;
} | [
"public",
"function",
"transformPrimitiveResource",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"resource",
"instanceof",
"Primitive",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Argument $resource should be an instance of League\\Fractal\\Resource\\Primitive'",
")",
";",
"}",
"$",
"transformer",
"=",
"$",
"this",
"->",
"resource",
"->",
"getTransformer",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"resource",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"transformer",
")",
"{",
"$",
"transformedData",
"=",
"$",
"data",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"transformer",
")",
")",
"{",
"$",
"transformedData",
"=",
"call_user_func",
"(",
"$",
"transformer",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"transformer",
"->",
"setCurrentScope",
"(",
"$",
"this",
")",
";",
"$",
"transformedData",
"=",
"$",
"transformer",
"->",
"transform",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"transformedData",
";",
"}"
] | Transformer a primitive resource
@return mixed | [
"Transformer",
"a",
"primitive",
"resource"
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Scope.php#L308-L329 | train |
thephpleague/fractal | src/Scope.php | Scope.serializeResource | protected function serializeResource(SerializerAbstract $serializer, $data)
{
$resourceKey = $this->resource->getResourceKey();
if ($this->resource instanceof Collection) {
return $serializer->collection($resourceKey, $data);
}
if ($this->resource instanceof Item) {
return $serializer->item($resourceKey, $data);
}
return $serializer->null();
} | php | protected function serializeResource(SerializerAbstract $serializer, $data)
{
$resourceKey = $this->resource->getResourceKey();
if ($this->resource instanceof Collection) {
return $serializer->collection($resourceKey, $data);
}
if ($this->resource instanceof Item) {
return $serializer->item($resourceKey, $data);
}
return $serializer->null();
} | [
"protected",
"function",
"serializeResource",
"(",
"SerializerAbstract",
"$",
"serializer",
",",
"$",
"data",
")",
"{",
"$",
"resourceKey",
"=",
"$",
"this",
"->",
"resource",
"->",
"getResourceKey",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"resource",
"instanceof",
"Collection",
")",
"{",
"return",
"$",
"serializer",
"->",
"collection",
"(",
"$",
"resourceKey",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"resource",
"instanceof",
"Item",
")",
"{",
"return",
"$",
"serializer",
"->",
"item",
"(",
"$",
"resourceKey",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"serializer",
"->",
"null",
"(",
")",
";",
"}"
] | Serialize a resource
@internal
@param SerializerAbstract $serializer
@param mixed $data
@return array | [
"Serialize",
"a",
"resource"
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Scope.php#L374-L387 | train |
thephpleague/fractal | src/Scope.php | Scope.fireTransformer | protected function fireTransformer($transformer, $data)
{
$includedData = [];
if (is_callable($transformer)) {
$transformedData = call_user_func($transformer, $data);
} else {
$transformer->setCurrentScope($this);
$transformedData = $transformer->transform($data);
}
if ($this->transformerHasIncludes($transformer)) {
$includedData = $this->fireIncludedTransformers($transformer, $data);
$transformedData = $this->manager->getSerializer()->mergeIncludes($transformedData, $includedData);
}
//Stick only with requested fields
$transformedData = $this->filterFieldsets($transformedData);
return [$transformedData, $includedData];
} | php | protected function fireTransformer($transformer, $data)
{
$includedData = [];
if (is_callable($transformer)) {
$transformedData = call_user_func($transformer, $data);
} else {
$transformer->setCurrentScope($this);
$transformedData = $transformer->transform($data);
}
if ($this->transformerHasIncludes($transformer)) {
$includedData = $this->fireIncludedTransformers($transformer, $data);
$transformedData = $this->manager->getSerializer()->mergeIncludes($transformedData, $includedData);
}
//Stick only with requested fields
$transformedData = $this->filterFieldsets($transformedData);
return [$transformedData, $includedData];
} | [
"protected",
"function",
"fireTransformer",
"(",
"$",
"transformer",
",",
"$",
"data",
")",
"{",
"$",
"includedData",
"=",
"[",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"transformer",
")",
")",
"{",
"$",
"transformedData",
"=",
"call_user_func",
"(",
"$",
"transformer",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"transformer",
"->",
"setCurrentScope",
"(",
"$",
"this",
")",
";",
"$",
"transformedData",
"=",
"$",
"transformer",
"->",
"transform",
"(",
"$",
"data",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"transformerHasIncludes",
"(",
"$",
"transformer",
")",
")",
"{",
"$",
"includedData",
"=",
"$",
"this",
"->",
"fireIncludedTransformers",
"(",
"$",
"transformer",
",",
"$",
"data",
")",
";",
"$",
"transformedData",
"=",
"$",
"this",
"->",
"manager",
"->",
"getSerializer",
"(",
")",
"->",
"mergeIncludes",
"(",
"$",
"transformedData",
",",
"$",
"includedData",
")",
";",
"}",
"//Stick only with requested fields",
"$",
"transformedData",
"=",
"$",
"this",
"->",
"filterFieldsets",
"(",
"$",
"transformedData",
")",
";",
"return",
"[",
"$",
"transformedData",
",",
"$",
"includedData",
"]",
";",
"}"
] | Fire the main transformer.
@internal
@param TransformerAbstract|callable $transformer
@param mixed $data
@return array | [
"Fire",
"the",
"main",
"transformer",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Scope.php#L399-L419 | train |
thephpleague/fractal | src/Scope.php | Scope.fireIncludedTransformers | protected function fireIncludedTransformers($transformer, $data)
{
$this->availableIncludes = $transformer->getAvailableIncludes();
return $transformer->processIncludedResources($this, $data) ?: [];
} | php | protected function fireIncludedTransformers($transformer, $data)
{
$this->availableIncludes = $transformer->getAvailableIncludes();
return $transformer->processIncludedResources($this, $data) ?: [];
} | [
"protected",
"function",
"fireIncludedTransformers",
"(",
"$",
"transformer",
",",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"availableIncludes",
"=",
"$",
"transformer",
"->",
"getAvailableIncludes",
"(",
")",
";",
"return",
"$",
"transformer",
"->",
"processIncludedResources",
"(",
"$",
"this",
",",
"$",
"data",
")",
"?",
":",
"[",
"]",
";",
"}"
] | Fire the included transformers.
@internal
@param \League\Fractal\TransformerAbstract $transformer
@param mixed $data
@return array | [
"Fire",
"the",
"included",
"transformers",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Scope.php#L431-L436 | train |
thephpleague/fractal | src/Scope.php | Scope.filterFieldsets | protected function filterFieldsets(array $data)
{
if (!$this->hasFilterFieldset()) {
return $data;
}
$serializer = $this->manager->getSerializer();
$requestedFieldset = iterator_to_array($this->getFilterFieldset());
//Build the array of requested fieldsets with the mandatory serializer fields
$filterFieldset = array_flip(
array_merge(
$serializer->getMandatoryFields(),
$requestedFieldset
)
);
return array_intersect_key($data, $filterFieldset);
} | php | protected function filterFieldsets(array $data)
{
if (!$this->hasFilterFieldset()) {
return $data;
}
$serializer = $this->manager->getSerializer();
$requestedFieldset = iterator_to_array($this->getFilterFieldset());
//Build the array of requested fieldsets with the mandatory serializer fields
$filterFieldset = array_flip(
array_merge(
$serializer->getMandatoryFields(),
$requestedFieldset
)
);
return array_intersect_key($data, $filterFieldset);
} | [
"protected",
"function",
"filterFieldsets",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasFilterFieldset",
"(",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"serializer",
"=",
"$",
"this",
"->",
"manager",
"->",
"getSerializer",
"(",
")",
";",
"$",
"requestedFieldset",
"=",
"iterator_to_array",
"(",
"$",
"this",
"->",
"getFilterFieldset",
"(",
")",
")",
";",
"//Build the array of requested fieldsets with the mandatory serializer fields",
"$",
"filterFieldset",
"=",
"array_flip",
"(",
"array_merge",
"(",
"$",
"serializer",
"->",
"getMandatoryFields",
"(",
")",
",",
"$",
"requestedFieldset",
")",
")",
";",
"return",
"array_intersect_key",
"(",
"$",
"data",
",",
"$",
"filterFieldset",
")",
";",
"}"
] | Filter the provided data with the requested filter fieldset for
the scope resource
@internal
@param array $data
@return array | [
"Filter",
"the",
"provided",
"data",
"with",
"the",
"requested",
"filter",
"fieldset",
"for",
"the",
"scope",
"resource"
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Scope.php#L479-L494 | train |
thephpleague/fractal | src/TransformerAbstract.php | TransformerAbstract.processIncludedResources | public function processIncludedResources(Scope $scope, $data)
{
$includedData = [];
$includes = $this->figureOutWhichIncludes($scope);
foreach ($includes as $include) {
$includedData = $this->includeResourceIfAvailable(
$scope,
$data,
$includedData,
$include
);
}
return $includedData === [] ? false : $includedData;
} | php | public function processIncludedResources(Scope $scope, $data)
{
$includedData = [];
$includes = $this->figureOutWhichIncludes($scope);
foreach ($includes as $include) {
$includedData = $this->includeResourceIfAvailable(
$scope,
$data,
$includedData,
$include
);
}
return $includedData === [] ? false : $includedData;
} | [
"public",
"function",
"processIncludedResources",
"(",
"Scope",
"$",
"scope",
",",
"$",
"data",
")",
"{",
"$",
"includedData",
"=",
"[",
"]",
";",
"$",
"includes",
"=",
"$",
"this",
"->",
"figureOutWhichIncludes",
"(",
"$",
"scope",
")",
";",
"foreach",
"(",
"$",
"includes",
"as",
"$",
"include",
")",
"{",
"$",
"includedData",
"=",
"$",
"this",
"->",
"includeResourceIfAvailable",
"(",
"$",
"scope",
",",
"$",
"data",
",",
"$",
"includedData",
",",
"$",
"include",
")",
";",
"}",
"return",
"$",
"includedData",
"===",
"[",
"]",
"?",
"false",
":",
"$",
"includedData",
";",
"}"
] | This method is fired to loop through available includes, see if any of
them are requested and permitted for this scope.
@internal
@param Scope $scope
@param mixed $data
@return array | [
"This",
"method",
"is",
"fired",
"to",
"loop",
"through",
"available",
"includes",
"see",
"if",
"any",
"of",
"them",
"are",
"requested",
"and",
"permitted",
"for",
"this",
"scope",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/TransformerAbstract.php#L120-L136 | train |
thephpleague/fractal | src/TransformerAbstract.php | TransformerAbstract.callIncludeMethod | protected function callIncludeMethod(Scope $scope, $includeName, $data)
{
$scopeIdentifier = $scope->getIdentifier($includeName);
$params = $scope->getManager()->getIncludeParams($scopeIdentifier);
// Check if the method name actually exists
$methodName = 'include'.str_replace(' ', '', ucwords(str_replace('_', ' ', str_replace('-', ' ', $includeName))));
$resource = call_user_func([$this, $methodName], $data, $params);
if ($resource === null) {
return false;
}
if (! $resource instanceof ResourceInterface) {
throw new \Exception(sprintf(
'Invalid return value from %s::%s(). Expected %s, received %s.',
__CLASS__,
$methodName,
'League\Fractal\Resource\ResourceInterface',
is_object($resource) ? get_class($resource) : gettype($resource)
));
}
return $resource;
} | php | protected function callIncludeMethod(Scope $scope, $includeName, $data)
{
$scopeIdentifier = $scope->getIdentifier($includeName);
$params = $scope->getManager()->getIncludeParams($scopeIdentifier);
// Check if the method name actually exists
$methodName = 'include'.str_replace(' ', '', ucwords(str_replace('_', ' ', str_replace('-', ' ', $includeName))));
$resource = call_user_func([$this, $methodName], $data, $params);
if ($resource === null) {
return false;
}
if (! $resource instanceof ResourceInterface) {
throw new \Exception(sprintf(
'Invalid return value from %s::%s(). Expected %s, received %s.',
__CLASS__,
$methodName,
'League\Fractal\Resource\ResourceInterface',
is_object($resource) ? get_class($resource) : gettype($resource)
));
}
return $resource;
} | [
"protected",
"function",
"callIncludeMethod",
"(",
"Scope",
"$",
"scope",
",",
"$",
"includeName",
",",
"$",
"data",
")",
"{",
"$",
"scopeIdentifier",
"=",
"$",
"scope",
"->",
"getIdentifier",
"(",
"$",
"includeName",
")",
";",
"$",
"params",
"=",
"$",
"scope",
"->",
"getManager",
"(",
")",
"->",
"getIncludeParams",
"(",
"$",
"scopeIdentifier",
")",
";",
"// Check if the method name actually exists",
"$",
"methodName",
"=",
"'include'",
".",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"str_replace",
"(",
"'-'",
",",
"' '",
",",
"$",
"includeName",
")",
")",
")",
")",
";",
"$",
"resource",
"=",
"call_user_func",
"(",
"[",
"$",
"this",
",",
"$",
"methodName",
"]",
",",
"$",
"data",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"resource",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"resource",
"instanceof",
"ResourceInterface",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Invalid return value from %s::%s(). Expected %s, received %s.'",
",",
"__CLASS__",
",",
"$",
"methodName",
",",
"'League\\Fractal\\Resource\\ResourceInterface'",
",",
"is_object",
"(",
"$",
"resource",
")",
"?",
"get_class",
"(",
"$",
"resource",
")",
":",
"gettype",
"(",
"$",
"resource",
")",
")",
")",
";",
"}",
"return",
"$",
"resource",
";",
"}"
] | Call Include Method.
@internal
@param Scope $scope
@param string $includeName
@param mixed $data
@throws \Exception
@return \League\Fractal\Resource\ResourceInterface | [
"Call",
"Include",
"Method",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/TransformerAbstract.php#L182-L207 | train |
thephpleague/fractal | src/TransformerAbstract.php | TransformerAbstract.primitive | protected function primitive($data, $transformer = null, $resourceKey = null)
{
return new Primitive($data, $transformer, $resourceKey);
} | php | protected function primitive($data, $transformer = null, $resourceKey = null)
{
return new Primitive($data, $transformer, $resourceKey);
} | [
"protected",
"function",
"primitive",
"(",
"$",
"data",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceKey",
"=",
"null",
")",
"{",
"return",
"new",
"Primitive",
"(",
"$",
"data",
",",
"$",
"transformer",
",",
"$",
"resourceKey",
")",
";",
"}"
] | Create a new primitive resource object.
@param mixed $data
@param callable|null $transformer
@param string $resourceKey
@return Primitive | [
"Create",
"a",
"new",
"primitive",
"resource",
"object",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/TransformerAbstract.php#L260-L263 | train |
thephpleague/fractal | src/Serializer/JsonApiSerializer.php | JsonApiSerializer.meta | public function meta(array $meta)
{
if (empty($meta)) {
return [];
}
$result['meta'] = $meta;
if (array_key_exists('pagination', $result['meta'])) {
$result['links'] = $result['meta']['pagination']['links'];
unset($result['meta']['pagination']['links']);
}
return $result;
} | php | public function meta(array $meta)
{
if (empty($meta)) {
return [];
}
$result['meta'] = $meta;
if (array_key_exists('pagination', $result['meta'])) {
$result['links'] = $result['meta']['pagination']['links'];
unset($result['meta']['pagination']['links']);
}
return $result;
} | [
"public",
"function",
"meta",
"(",
"array",
"$",
"meta",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"meta",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"result",
"[",
"'meta'",
"]",
"=",
"$",
"meta",
";",
"if",
"(",
"array_key_exists",
"(",
"'pagination'",
",",
"$",
"result",
"[",
"'meta'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'links'",
"]",
"=",
"$",
"result",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
"[",
"'links'",
"]",
";",
"unset",
"(",
"$",
"result",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
"[",
"'links'",
"]",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Serialize the meta.
@param array $meta
@return array | [
"Serialize",
"the",
"meta",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Serializer/JsonApiSerializer.php#L146-L160 | train |
thephpleague/fractal | src/Serializer/JsonApiSerializer.php | JsonApiSerializer.includedData | public function includedData(ResourceInterface $resource, array $data)
{
list($serializedData, $linkedIds) = $this->pullOutNestedIncludedData($data);
foreach ($data as $value) {
foreach ($value as $includeObject) {
if ($this->isNull($includeObject) || $this->isEmpty($includeObject)) {
continue;
}
$includeObjects = $this->createIncludeObjects($includeObject);
list($serializedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey($includeObjects, $linkedIds, $serializedData);
}
}
return empty($serializedData) ? [] : ['included' => $serializedData];
} | php | public function includedData(ResourceInterface $resource, array $data)
{
list($serializedData, $linkedIds) = $this->pullOutNestedIncludedData($data);
foreach ($data as $value) {
foreach ($value as $includeObject) {
if ($this->isNull($includeObject) || $this->isEmpty($includeObject)) {
continue;
}
$includeObjects = $this->createIncludeObjects($includeObject);
list($serializedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey($includeObjects, $linkedIds, $serializedData);
}
}
return empty($serializedData) ? [] : ['included' => $serializedData];
} | [
"public",
"function",
"includedData",
"(",
"ResourceInterface",
"$",
"resource",
",",
"array",
"$",
"data",
")",
"{",
"list",
"(",
"$",
"serializedData",
",",
"$",
"linkedIds",
")",
"=",
"$",
"this",
"->",
"pullOutNestedIncludedData",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"includeObject",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNull",
"(",
"$",
"includeObject",
")",
"||",
"$",
"this",
"->",
"isEmpty",
"(",
"$",
"includeObject",
")",
")",
"{",
"continue",
";",
"}",
"$",
"includeObjects",
"=",
"$",
"this",
"->",
"createIncludeObjects",
"(",
"$",
"includeObject",
")",
";",
"list",
"(",
"$",
"serializedData",
",",
"$",
"linkedIds",
")",
"=",
"$",
"this",
"->",
"serializeIncludedObjectsWithCacheKey",
"(",
"$",
"includeObjects",
",",
"$",
"linkedIds",
",",
"$",
"serializedData",
")",
";",
"}",
"}",
"return",
"empty",
"(",
"$",
"serializedData",
")",
"?",
"[",
"]",
":",
"[",
"'included'",
"=>",
"$",
"serializedData",
"]",
";",
"}"
] | Serialize the included data.
@param ResourceInterface $resource
@param array $data
@return array | [
"Serialize",
"the",
"included",
"data",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Serializer/JsonApiSerializer.php#L180-L196 | train |
thephpleague/fractal | src/Serializer/JsonApiSerializer.php | JsonApiSerializer.filterIncludes | public function filterIncludes($includedData, $data)
{
if (!isset($includedData['included'])) {
return $includedData;
}
// Create the RootObjects
$this->createRootObjects($data);
// Filter out the root objects
$filteredIncludes = array_filter($includedData['included'], [$this, 'filterRootObject']);
// Reset array indizes
$includedData['included'] = array_merge([], $filteredIncludes);
return $includedData;
} | php | public function filterIncludes($includedData, $data)
{
if (!isset($includedData['included'])) {
return $includedData;
}
// Create the RootObjects
$this->createRootObjects($data);
// Filter out the root objects
$filteredIncludes = array_filter($includedData['included'], [$this, 'filterRootObject']);
// Reset array indizes
$includedData['included'] = array_merge([], $filteredIncludes);
return $includedData;
} | [
"public",
"function",
"filterIncludes",
"(",
"$",
"includedData",
",",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"includedData",
"[",
"'included'",
"]",
")",
")",
"{",
"return",
"$",
"includedData",
";",
"}",
"// Create the RootObjects",
"$",
"this",
"->",
"createRootObjects",
"(",
"$",
"data",
")",
";",
"// Filter out the root objects",
"$",
"filteredIncludes",
"=",
"array_filter",
"(",
"$",
"includedData",
"[",
"'included'",
"]",
",",
"[",
"$",
"this",
",",
"'filterRootObject'",
"]",
")",
";",
"// Reset array indizes",
"$",
"includedData",
"[",
"'included'",
"]",
"=",
"array_merge",
"(",
"[",
"]",
",",
"$",
"filteredIncludes",
")",
";",
"return",
"$",
"includedData",
";",
"}"
] | Hook to manipulate the final sideloaded includes.
The JSON API specification does not allow the root object to be included
into the sideloaded `included`-array. We have to make sure it is
filtered out, in case some object links to the root object in a
relationship.
@param array $includedData
@param array $data
@return array | [
"Hook",
"to",
"manipulate",
"the",
"final",
"sideloaded",
"includes",
".",
"The",
"JSON",
"API",
"specification",
"does",
"not",
"allow",
"the",
"root",
"object",
"to",
"be",
"included",
"into",
"the",
"sideloaded",
"included",
"-",
"array",
".",
"We",
"have",
"to",
"make",
"sure",
"it",
"is",
"filtered",
"out",
"in",
"case",
"some",
"object",
"links",
"to",
"the",
"root",
"object",
"in",
"a",
"relationship",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Serializer/JsonApiSerializer.php#L237-L253 | train |
thephpleague/fractal | src/Serializer/JsonApiSerializer.php | JsonApiSerializer.pullOutNestedIncludedData | protected function pullOutNestedIncludedData(array $data)
{
$includedData = [];
$linkedIds = [];
foreach ($data as $value) {
foreach ($value as $includeObject) {
if (isset($includeObject['included'])) {
list($includedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey($includeObject['included'], $linkedIds, $includedData);
}
}
}
return [$includedData, $linkedIds];
} | php | protected function pullOutNestedIncludedData(array $data)
{
$includedData = [];
$linkedIds = [];
foreach ($data as $value) {
foreach ($value as $includeObject) {
if (isset($includeObject['included'])) {
list($includedData, $linkedIds) = $this->serializeIncludedObjectsWithCacheKey($includeObject['included'], $linkedIds, $includedData);
}
}
}
return [$includedData, $linkedIds];
} | [
"protected",
"function",
"pullOutNestedIncludedData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"includedData",
"=",
"[",
"]",
";",
"$",
"linkedIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"includeObject",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"includeObject",
"[",
"'included'",
"]",
")",
")",
"{",
"list",
"(",
"$",
"includedData",
",",
"$",
"linkedIds",
")",
"=",
"$",
"this",
"->",
"serializeIncludedObjectsWithCacheKey",
"(",
"$",
"includeObject",
"[",
"'included'",
"]",
",",
"$",
"linkedIds",
",",
"$",
"includedData",
")",
";",
"}",
"}",
"}",
"return",
"[",
"$",
"includedData",
",",
"$",
"linkedIds",
"]",
";",
"}"
] | Keep all sideloaded inclusion data on the top level.
@param array $data
@return array | [
"Keep",
"all",
"sideloaded",
"inclusion",
"data",
"on",
"the",
"top",
"level",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Serializer/JsonApiSerializer.php#L397-L411 | train |
thephpleague/fractal | src/Serializer/JsonApiSerializer.php | JsonApiSerializer.createIncludeObjects | private function createIncludeObjects($includeObject)
{
if ($this->isCollection($includeObject)) {
$includeObjects = $includeObject['data'];
return $includeObjects;
} else {
$includeObjects = [$includeObject['data']];
return $includeObjects;
}
} | php | private function createIncludeObjects($includeObject)
{
if ($this->isCollection($includeObject)) {
$includeObjects = $includeObject['data'];
return $includeObjects;
} else {
$includeObjects = [$includeObject['data']];
return $includeObjects;
}
} | [
"private",
"function",
"createIncludeObjects",
"(",
"$",
"includeObject",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCollection",
"(",
"$",
"includeObject",
")",
")",
"{",
"$",
"includeObjects",
"=",
"$",
"includeObject",
"[",
"'data'",
"]",
";",
"return",
"$",
"includeObjects",
";",
"}",
"else",
"{",
"$",
"includeObjects",
"=",
"[",
"$",
"includeObject",
"[",
"'data'",
"]",
"]",
";",
"return",
"$",
"includeObjects",
";",
"}",
"}"
] | Check if the objects are part of a collection or not
@param $includeObject
@return array | [
"Check",
"if",
"the",
"objects",
"are",
"part",
"of",
"a",
"collection",
"or",
"not"
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Serializer/JsonApiSerializer.php#L430-L441 | train |
thephpleague/fractal | src/Serializer/JsonApiSerializer.php | JsonApiSerializer.createRootObjects | private function createRootObjects($data)
{
if ($this->isCollection($data)) {
$this->setRootObjects($data['data']);
} else {
$this->setRootObjects([$data['data']]);
}
} | php | private function createRootObjects($data)
{
if ($this->isCollection($data)) {
$this->setRootObjects($data['data']);
} else {
$this->setRootObjects([$data['data']]);
}
} | [
"private",
"function",
"createRootObjects",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCollection",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"setRootObjects",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setRootObjects",
"(",
"[",
"$",
"data",
"[",
"'data'",
"]",
"]",
")",
";",
"}",
"}"
] | Sets the RootObjects, either as collection or not.
@param $data | [
"Sets",
"the",
"RootObjects",
"either",
"as",
"collection",
"or",
"not",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Serializer/JsonApiSerializer.php#L448-L455 | train |
thephpleague/fractal | src/Serializer/JsonApiSerializer.php | JsonApiSerializer.fillRelationshipAsCollection | private function fillRelationshipAsCollection($data, $relationship, $key)
{
foreach ($relationship as $index => $relationshipData) {
$data['data'][$index]['relationships'][$key] = $relationshipData;
if ($this->shouldIncludeLinks()) {
$data['data'][$index]['relationships'][$key] = array_merge([
'links' => [
'self' => "{$this->baseUrl}/{$data['data'][$index]['type']}/{$data['data'][$index]['id']}/relationships/$key",
'related' => "{$this->baseUrl}/{$data['data'][$index]['type']}/{$data['data'][$index]['id']}/$key",
],
], $data['data'][$index]['relationships'][$key]);
}
}
return $data;
} | php | private function fillRelationshipAsCollection($data, $relationship, $key)
{
foreach ($relationship as $index => $relationshipData) {
$data['data'][$index]['relationships'][$key] = $relationshipData;
if ($this->shouldIncludeLinks()) {
$data['data'][$index]['relationships'][$key] = array_merge([
'links' => [
'self' => "{$this->baseUrl}/{$data['data'][$index]['type']}/{$data['data'][$index]['id']}/relationships/$key",
'related' => "{$this->baseUrl}/{$data['data'][$index]['type']}/{$data['data'][$index]['id']}/$key",
],
], $data['data'][$index]['relationships'][$key]);
}
}
return $data;
} | [
"private",
"function",
"fillRelationshipAsCollection",
"(",
"$",
"data",
",",
"$",
"relationship",
",",
"$",
"key",
")",
"{",
"foreach",
"(",
"$",
"relationship",
"as",
"$",
"index",
"=>",
"$",
"relationshipData",
")",
"{",
"$",
"data",
"[",
"'data'",
"]",
"[",
"$",
"index",
"]",
"[",
"'relationships'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"relationshipData",
";",
"if",
"(",
"$",
"this",
"->",
"shouldIncludeLinks",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'data'",
"]",
"[",
"$",
"index",
"]",
"[",
"'relationships'",
"]",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"[",
"'links'",
"=>",
"[",
"'self'",
"=>",
"\"{$this->baseUrl}/{$data['data'][$index]['type']}/{$data['data'][$index]['id']}/relationships/$key\"",
",",
"'related'",
"=>",
"\"{$this->baseUrl}/{$data['data'][$index]['type']}/{$data['data'][$index]['id']}/$key\"",
",",
"]",
",",
"]",
",",
"$",
"data",
"[",
"'data'",
"]",
"[",
"$",
"index",
"]",
"[",
"'relationships'",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Loops over the relationships of the provided data and formats it
@param $data
@param $relationship
@param $key
@return array | [
"Loops",
"over",
"the",
"relationships",
"of",
"the",
"provided",
"data",
"and",
"formats",
"it"
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Serializer/JsonApiSerializer.php#L467-L483 | train |
thephpleague/fractal | src/Manager.php | Manager.createData | public function createData(ResourceInterface $resource, $scopeIdentifier = null, Scope $parentScopeInstance = null)
{
if ($parentScopeInstance !== null) {
return $this->scopeFactory->createChildScopeFor($this, $parentScopeInstance, $resource, $scopeIdentifier);
}
return $this->scopeFactory->createScopeFor($this, $resource, $scopeIdentifier);
} | php | public function createData(ResourceInterface $resource, $scopeIdentifier = null, Scope $parentScopeInstance = null)
{
if ($parentScopeInstance !== null) {
return $this->scopeFactory->createChildScopeFor($this, $parentScopeInstance, $resource, $scopeIdentifier);
}
return $this->scopeFactory->createScopeFor($this, $resource, $scopeIdentifier);
} | [
"public",
"function",
"createData",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"scopeIdentifier",
"=",
"null",
",",
"Scope",
"$",
"parentScopeInstance",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"parentScopeInstance",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"scopeFactory",
"->",
"createChildScopeFor",
"(",
"$",
"this",
",",
"$",
"parentScopeInstance",
",",
"$",
"resource",
",",
"$",
"scopeIdentifier",
")",
";",
"}",
"return",
"$",
"this",
"->",
"scopeFactory",
"->",
"createScopeFor",
"(",
"$",
"this",
",",
"$",
"resource",
",",
"$",
"scopeIdentifier",
")",
";",
"}"
] | Create Data.
Main method to kick this all off. Make a resource then pass it over, and use toArray()
@param ResourceInterface $resource
@param string $scopeIdentifier
@param Scope $parentScopeInstance
@return Scope | [
"Create",
"Data",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Manager.php#L99-L106 | train |
thephpleague/fractal | src/Manager.php | Manager.parseIncludes | public function parseIncludes($includes)
{
// Wipe these before we go again
$this->requestedIncludes = $this->includeParams = [];
if (is_string($includes)) {
$includes = explode(',', $includes);
}
if (! is_array($includes)) {
throw new \InvalidArgumentException(
'The parseIncludes() method expects a string or an array. '.gettype($includes).' given'
);
}
foreach ($includes as $include) {
list($includeName, $allModifiersStr) = array_pad(explode(':', $include, 2), 2, null);
// Trim it down to a cool level of recursion
$includeName = $this->trimToAcceptableRecursionLevel($includeName);
if (in_array($includeName, $this->requestedIncludes)) {
continue;
}
$this->requestedIncludes[] = $includeName;
// No Params? Bored
if ($allModifiersStr === null) {
continue;
}
// Matches multiple instances of 'something(foo|bar|baz)' in the string
// I guess it ignores : so you could use anything, but probably don't do that
preg_match_all('/([\w]+)(\(([^\)]+)\))?/', $allModifiersStr, $allModifiersArr);
// [0] is full matched strings...
$modifierCount = count($allModifiersArr[0]);
$modifierArr = [];
for ($modifierIt = 0; $modifierIt < $modifierCount; $modifierIt++) {
// [1] is the modifier
$modifierName = $allModifiersArr[1][$modifierIt];
// and [3] is delimited params
$modifierParamStr = $allModifiersArr[3][$modifierIt];
// Make modifier array key with an array of params as the value
$modifierArr[$modifierName] = explode($this->paramDelimiter, $modifierParamStr);
}
$this->includeParams[$includeName] = $modifierArr;
}
// This should be optional and public someday, but without it includes would never show up
$this->autoIncludeParents();
return $this;
} | php | public function parseIncludes($includes)
{
// Wipe these before we go again
$this->requestedIncludes = $this->includeParams = [];
if (is_string($includes)) {
$includes = explode(',', $includes);
}
if (! is_array($includes)) {
throw new \InvalidArgumentException(
'The parseIncludes() method expects a string or an array. '.gettype($includes).' given'
);
}
foreach ($includes as $include) {
list($includeName, $allModifiersStr) = array_pad(explode(':', $include, 2), 2, null);
// Trim it down to a cool level of recursion
$includeName = $this->trimToAcceptableRecursionLevel($includeName);
if (in_array($includeName, $this->requestedIncludes)) {
continue;
}
$this->requestedIncludes[] = $includeName;
// No Params? Bored
if ($allModifiersStr === null) {
continue;
}
// Matches multiple instances of 'something(foo|bar|baz)' in the string
// I guess it ignores : so you could use anything, but probably don't do that
preg_match_all('/([\w]+)(\(([^\)]+)\))?/', $allModifiersStr, $allModifiersArr);
// [0] is full matched strings...
$modifierCount = count($allModifiersArr[0]);
$modifierArr = [];
for ($modifierIt = 0; $modifierIt < $modifierCount; $modifierIt++) {
// [1] is the modifier
$modifierName = $allModifiersArr[1][$modifierIt];
// and [3] is delimited params
$modifierParamStr = $allModifiersArr[3][$modifierIt];
// Make modifier array key with an array of params as the value
$modifierArr[$modifierName] = explode($this->paramDelimiter, $modifierParamStr);
}
$this->includeParams[$includeName] = $modifierArr;
}
// This should be optional and public someday, but without it includes would never show up
$this->autoIncludeParents();
return $this;
} | [
"public",
"function",
"parseIncludes",
"(",
"$",
"includes",
")",
"{",
"// Wipe these before we go again",
"$",
"this",
"->",
"requestedIncludes",
"=",
"$",
"this",
"->",
"includeParams",
"=",
"[",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"includes",
")",
")",
"{",
"$",
"includes",
"=",
"explode",
"(",
"','",
",",
"$",
"includes",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"includes",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The parseIncludes() method expects a string or an array. '",
".",
"gettype",
"(",
"$",
"includes",
")",
".",
"' given'",
")",
";",
"}",
"foreach",
"(",
"$",
"includes",
"as",
"$",
"include",
")",
"{",
"list",
"(",
"$",
"includeName",
",",
"$",
"allModifiersStr",
")",
"=",
"array_pad",
"(",
"explode",
"(",
"':'",
",",
"$",
"include",
",",
"2",
")",
",",
"2",
",",
"null",
")",
";",
"// Trim it down to a cool level of recursion",
"$",
"includeName",
"=",
"$",
"this",
"->",
"trimToAcceptableRecursionLevel",
"(",
"$",
"includeName",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"includeName",
",",
"$",
"this",
"->",
"requestedIncludes",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"requestedIncludes",
"[",
"]",
"=",
"$",
"includeName",
";",
"// No Params? Bored",
"if",
"(",
"$",
"allModifiersStr",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"// Matches multiple instances of 'something(foo|bar|baz)' in the string",
"// I guess it ignores : so you could use anything, but probably don't do that",
"preg_match_all",
"(",
"'/([\\w]+)(\\(([^\\)]+)\\))?/'",
",",
"$",
"allModifiersStr",
",",
"$",
"allModifiersArr",
")",
";",
"// [0] is full matched strings...",
"$",
"modifierCount",
"=",
"count",
"(",
"$",
"allModifiersArr",
"[",
"0",
"]",
")",
";",
"$",
"modifierArr",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"modifierIt",
"=",
"0",
";",
"$",
"modifierIt",
"<",
"$",
"modifierCount",
";",
"$",
"modifierIt",
"++",
")",
"{",
"// [1] is the modifier",
"$",
"modifierName",
"=",
"$",
"allModifiersArr",
"[",
"1",
"]",
"[",
"$",
"modifierIt",
"]",
";",
"// and [3] is delimited params",
"$",
"modifierParamStr",
"=",
"$",
"allModifiersArr",
"[",
"3",
"]",
"[",
"$",
"modifierIt",
"]",
";",
"// Make modifier array key with an array of params as the value",
"$",
"modifierArr",
"[",
"$",
"modifierName",
"]",
"=",
"explode",
"(",
"$",
"this",
"->",
"paramDelimiter",
",",
"$",
"modifierParamStr",
")",
";",
"}",
"$",
"this",
"->",
"includeParams",
"[",
"$",
"includeName",
"]",
"=",
"$",
"modifierArr",
";",
"}",
"// This should be optional and public someday, but without it includes would never show up",
"$",
"this",
"->",
"autoIncludeParents",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Parse Include String.
@param array|string $includes Array or csv string of resources to include
@return $this | [
"Parse",
"Include",
"String",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Manager.php#L163-L221 | train |
thephpleague/fractal | src/Manager.php | Manager.getFieldset | public function getFieldset($type)
{
return !isset($this->requestedFieldsets[$type]) ?
null :
new ParamBag($this->requestedFieldsets[$type]);
} | php | public function getFieldset($type)
{
return !isset($this->requestedFieldsets[$type]) ?
null :
new ParamBag($this->requestedFieldsets[$type]);
} | [
"public",
"function",
"getFieldset",
"(",
"$",
"type",
")",
"{",
"return",
"!",
"isset",
"(",
"$",
"this",
"->",
"requestedFieldsets",
"[",
"$",
"type",
"]",
")",
"?",
"null",
":",
"new",
"ParamBag",
"(",
"$",
"this",
"->",
"requestedFieldsets",
"[",
"$",
"type",
"]",
")",
";",
"}"
] | Get fieldset params for the specified type.
@param string $type
@return \League\Fractal\ParamBag|null | [
"Get",
"fieldset",
"params",
"for",
"the",
"specified",
"type",
"."
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Manager.php#L263-L268 | train |
thephpleague/fractal | src/Manager.php | Manager.autoIncludeParents | protected function autoIncludeParents()
{
$parsed = [];
foreach ($this->requestedIncludes as $include) {
$nested = explode('.', $include);
$part = array_shift($nested);
$parsed[] = $part;
while (count($nested) > 0) {
$part .= '.'.array_shift($nested);
$parsed[] = $part;
}
}
$this->requestedIncludes = array_values(array_unique($parsed));
} | php | protected function autoIncludeParents()
{
$parsed = [];
foreach ($this->requestedIncludes as $include) {
$nested = explode('.', $include);
$part = array_shift($nested);
$parsed[] = $part;
while (count($nested) > 0) {
$part .= '.'.array_shift($nested);
$parsed[] = $part;
}
}
$this->requestedIncludes = array_values(array_unique($parsed));
} | [
"protected",
"function",
"autoIncludeParents",
"(",
")",
"{",
"$",
"parsed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"requestedIncludes",
"as",
"$",
"include",
")",
"{",
"$",
"nested",
"=",
"explode",
"(",
"'.'",
",",
"$",
"include",
")",
";",
"$",
"part",
"=",
"array_shift",
"(",
"$",
"nested",
")",
";",
"$",
"parsed",
"[",
"]",
"=",
"$",
"part",
";",
"while",
"(",
"count",
"(",
"$",
"nested",
")",
">",
"0",
")",
"{",
"$",
"part",
".=",
"'.'",
".",
"array_shift",
"(",
"$",
"nested",
")",
";",
"$",
"parsed",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"}",
"$",
"this",
"->",
"requestedIncludes",
"=",
"array_values",
"(",
"array_unique",
"(",
"$",
"parsed",
")",
")",
";",
"}"
] | Auto-include Parents
Look at the requested includes and automatically include the parents if they
are not explicitly requested. E.g: [foo, bar.baz] becomes [foo, bar, bar.baz]
@internal
@return void | [
"Auto",
"-",
"include",
"Parents"
] | c08a0f6db4dbc58d12e934e12203d2c2d5553409 | https://github.com/thephpleague/fractal/blob/c08a0f6db4dbc58d12e934e12203d2c2d5553409/src/Manager.php#L342-L359 | train |
Wixel/GUMP | gump.class.php | GUMP.filter_input | public static function filter_input(array $data, array $filters)
{
$gump = self::get_instance();
return $gump->filter($data, $filters);
} | php | public static function filter_input(array $data, array $filters)
{
$gump = self::get_instance();
return $gump->filter($data, $filters);
} | [
"public",
"static",
"function",
"filter_input",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"filters",
")",
"{",
"$",
"gump",
"=",
"self",
"::",
"get_instance",
"(",
")",
";",
"return",
"$",
"gump",
"->",
"filter",
"(",
"$",
"data",
",",
"$",
"filters",
")",
";",
"}"
] | Shorthand method for running only the data filters.
@param array $data
@param array $filters
@return mixed | [
"Shorthand",
"method",
"for",
"running",
"only",
"the",
"data",
"filters",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L117-L122 | train |
Wixel/GUMP | gump.class.php | GUMP.sanitize | public function sanitize(array $input, array $fields = array(), $utf8_encode = true)
{
$magic_quotes = (bool) get_magic_quotes_gpc();
if (empty($fields)) {
$fields = array_keys($input);
}
$return = array();
foreach ($fields as $field) {
if (!isset($input[$field])) {
continue;
} else {
$value = $input[$field];
if (is_array($value)) {
$value = $this->sanitize($value);
}
if (is_string($value)) {
if ($magic_quotes === true) {
$value = stripslashes($value);
}
if (strpos($value, "\r") !== false) {
$value = trim($value);
}
if (function_exists('iconv') && function_exists('mb_detect_encoding') && $utf8_encode) {
$current_encoding = mb_detect_encoding($value);
if ($current_encoding != 'UTF-8' && $current_encoding != 'UTF-16') {
$value = iconv($current_encoding, 'UTF-8', $value);
}
}
$value = filter_var($value, FILTER_SANITIZE_STRING);
}
$return[$field] = $value;
}
}
return $return;
} | php | public function sanitize(array $input, array $fields = array(), $utf8_encode = true)
{
$magic_quotes = (bool) get_magic_quotes_gpc();
if (empty($fields)) {
$fields = array_keys($input);
}
$return = array();
foreach ($fields as $field) {
if (!isset($input[$field])) {
continue;
} else {
$value = $input[$field];
if (is_array($value)) {
$value = $this->sanitize($value);
}
if (is_string($value)) {
if ($magic_quotes === true) {
$value = stripslashes($value);
}
if (strpos($value, "\r") !== false) {
$value = trim($value);
}
if (function_exists('iconv') && function_exists('mb_detect_encoding') && $utf8_encode) {
$current_encoding = mb_detect_encoding($value);
if ($current_encoding != 'UTF-8' && $current_encoding != 'UTF-16') {
$value = iconv($current_encoding, 'UTF-8', $value);
}
}
$value = filter_var($value, FILTER_SANITIZE_STRING);
}
$return[$field] = $value;
}
}
return $return;
} | [
"public",
"function",
"sanitize",
"(",
"array",
"$",
"input",
",",
"array",
"$",
"fields",
"=",
"array",
"(",
")",
",",
"$",
"utf8_encode",
"=",
"true",
")",
"{",
"$",
"magic_quotes",
"=",
"(",
"bool",
")",
"get_magic_quotes_gpc",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"array_keys",
"(",
"$",
"input",
")",
";",
"}",
"$",
"return",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"continue",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"input",
"[",
"$",
"field",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"sanitize",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"magic_quotes",
"===",
"true",
")",
"{",
"$",
"value",
"=",
"stripslashes",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"\"\\r\"",
")",
"!==",
"false",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'iconv'",
")",
"&&",
"function_exists",
"(",
"'mb_detect_encoding'",
")",
"&&",
"$",
"utf8_encode",
")",
"{",
"$",
"current_encoding",
"=",
"mb_detect_encoding",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"current_encoding",
"!=",
"'UTF-8'",
"&&",
"$",
"current_encoding",
"!=",
"'UTF-16'",
")",
"{",
"$",
"value",
"=",
"iconv",
"(",
"$",
"current_encoding",
",",
"'UTF-8'",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"value",
"=",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"}",
"$",
"return",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Sanitize the input data.
@param array $input
@param null $fields
@param bool $utf8_encode
@return array | [
"Sanitize",
"the",
"input",
"data",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L317-L360 | train |
Wixel/GUMP | gump.class.php | GUMP.set_error_message | public static function set_error_message($rule, $message)
{
$gump = self::get_instance();
self::$validation_methods_errors[$rule] = $message;
} | php | public static function set_error_message($rule, $message)
{
$gump = self::get_instance();
self::$validation_methods_errors[$rule] = $message;
} | [
"public",
"static",
"function",
"set_error_message",
"(",
"$",
"rule",
",",
"$",
"message",
")",
"{",
"$",
"gump",
"=",
"self",
"::",
"get_instance",
"(",
")",
";",
"self",
"::",
"$",
"validation_methods_errors",
"[",
"$",
"rule",
"]",
"=",
"$",
"message",
";",
"}"
] | Set a custom error message for a validation rule.
@param string $rule
@param string $message | [
"Set",
"a",
"custom",
"error",
"message",
"for",
"a",
"validation",
"rule",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L508-L512 | train |
Wixel/GUMP | gump.class.php | GUMP.get_messages | protected function get_messages()
{
$lang_file = __DIR__.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$this->lang.'.php';
$messages = require $lang_file;
if ($validation_methods_errors = self::$validation_methods_errors) {
$messages = array_merge($messages, $validation_methods_errors);
}
return $messages;
} | php | protected function get_messages()
{
$lang_file = __DIR__.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$this->lang.'.php';
$messages = require $lang_file;
if ($validation_methods_errors = self::$validation_methods_errors) {
$messages = array_merge($messages, $validation_methods_errors);
}
return $messages;
} | [
"protected",
"function",
"get_messages",
"(",
")",
"{",
"$",
"lang_file",
"=",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
".",
"'lang'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"lang",
".",
"'.php'",
";",
"$",
"messages",
"=",
"require",
"$",
"lang_file",
";",
"if",
"(",
"$",
"validation_methods_errors",
"=",
"self",
"::",
"$",
"validation_methods_errors",
")",
"{",
"$",
"messages",
"=",
"array_merge",
"(",
"$",
"messages",
",",
"$",
"validation_methods_errors",
")",
";",
"}",
"return",
"$",
"messages",
";",
"}"
] | Get error messages.
@return array | [
"Get",
"error",
"messages",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L538-L547 | train |
Wixel/GUMP | gump.class.php | GUMP.get_readable_errors | public function get_readable_errors($convert_to_string = false, $field_class = 'gump-field', $error_class = 'gump-error-message')
{
if (empty($this->errors)) {
return ($convert_to_string) ? null : array();
}
$resp = array();
// Error messages
$messages = $this->get_messages();
foreach ($this->errors as $e) {
$field = ucwords(str_replace($this->fieldCharsToRemove, chr(32), $e['field']));
$param = $e['param'];
// Let's fetch explicitly if the field names exist
if (array_key_exists($e['field'], self::$fields)) {
$field = self::$fields[$e['field']];
// If param is a field (i.e. equalsfield validator)
if (array_key_exists($param, self::$fields)) {
$param = self::$fields[$e['param']];
}
}
// Messages
if (isset($messages[$e['rule']])) {
if (is_array($param)) {
$param = implode(', ', $param);
}
$message = str_replace('{param}', $param, str_replace('{field}', '<span class="'.$field_class.'">'.$field.'</span>', $messages[$e['rule']]));
$resp[] = $message;
} else {
throw new \Exception ('Rule "'.$e['rule'].'" does not have an error message');
}
}
if (!$convert_to_string) {
return $resp;
} else {
$buffer = '';
foreach ($resp as $s) {
$buffer .= "<span class=\"$error_class\">$s</span>";
}
return $buffer;
}
} | php | public function get_readable_errors($convert_to_string = false, $field_class = 'gump-field', $error_class = 'gump-error-message')
{
if (empty($this->errors)) {
return ($convert_to_string) ? null : array();
}
$resp = array();
// Error messages
$messages = $this->get_messages();
foreach ($this->errors as $e) {
$field = ucwords(str_replace($this->fieldCharsToRemove, chr(32), $e['field']));
$param = $e['param'];
// Let's fetch explicitly if the field names exist
if (array_key_exists($e['field'], self::$fields)) {
$field = self::$fields[$e['field']];
// If param is a field (i.e. equalsfield validator)
if (array_key_exists($param, self::$fields)) {
$param = self::$fields[$e['param']];
}
}
// Messages
if (isset($messages[$e['rule']])) {
if (is_array($param)) {
$param = implode(', ', $param);
}
$message = str_replace('{param}', $param, str_replace('{field}', '<span class="'.$field_class.'">'.$field.'</span>', $messages[$e['rule']]));
$resp[] = $message;
} else {
throw new \Exception ('Rule "'.$e['rule'].'" does not have an error message');
}
}
if (!$convert_to_string) {
return $resp;
} else {
$buffer = '';
foreach ($resp as $s) {
$buffer .= "<span class=\"$error_class\">$s</span>";
}
return $buffer;
}
} | [
"public",
"function",
"get_readable_errors",
"(",
"$",
"convert_to_string",
"=",
"false",
",",
"$",
"field_class",
"=",
"'gump-field'",
",",
"$",
"error_class",
"=",
"'gump-error-message'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"errors",
")",
")",
"{",
"return",
"(",
"$",
"convert_to_string",
")",
"?",
"null",
":",
"array",
"(",
")",
";",
"}",
"$",
"resp",
"=",
"array",
"(",
")",
";",
"// Error messages",
"$",
"messages",
"=",
"$",
"this",
"->",
"get_messages",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"errors",
"as",
"$",
"e",
")",
"{",
"$",
"field",
"=",
"ucwords",
"(",
"str_replace",
"(",
"$",
"this",
"->",
"fieldCharsToRemove",
",",
"chr",
"(",
"32",
")",
",",
"$",
"e",
"[",
"'field'",
"]",
")",
")",
";",
"$",
"param",
"=",
"$",
"e",
"[",
"'param'",
"]",
";",
"// Let's fetch explicitly if the field names exist",
"if",
"(",
"array_key_exists",
"(",
"$",
"e",
"[",
"'field'",
"]",
",",
"self",
"::",
"$",
"fields",
")",
")",
"{",
"$",
"field",
"=",
"self",
"::",
"$",
"fields",
"[",
"$",
"e",
"[",
"'field'",
"]",
"]",
";",
"// If param is a field (i.e. equalsfield validator)",
"if",
"(",
"array_key_exists",
"(",
"$",
"param",
",",
"self",
"::",
"$",
"fields",
")",
")",
"{",
"$",
"param",
"=",
"self",
"::",
"$",
"fields",
"[",
"$",
"e",
"[",
"'param'",
"]",
"]",
";",
"}",
"}",
"// Messages",
"if",
"(",
"isset",
"(",
"$",
"messages",
"[",
"$",
"e",
"[",
"'rule'",
"]",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"param",
")",
")",
"{",
"$",
"param",
"=",
"implode",
"(",
"', '",
",",
"$",
"param",
")",
";",
"}",
"$",
"message",
"=",
"str_replace",
"(",
"'{param}'",
",",
"$",
"param",
",",
"str_replace",
"(",
"'{field}'",
",",
"'<span class=\"'",
".",
"$",
"field_class",
".",
"'\">'",
".",
"$",
"field",
".",
"'</span>'",
",",
"$",
"messages",
"[",
"$",
"e",
"[",
"'rule'",
"]",
"]",
")",
")",
";",
"$",
"resp",
"[",
"]",
"=",
"$",
"message",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Rule \"'",
".",
"$",
"e",
"[",
"'rule'",
"]",
".",
"'\" does not have an error message'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"convert_to_string",
")",
"{",
"return",
"$",
"resp",
";",
"}",
"else",
"{",
"$",
"buffer",
"=",
"''",
";",
"foreach",
"(",
"$",
"resp",
"as",
"$",
"s",
")",
"{",
"$",
"buffer",
".=",
"\"<span class=\\\"$error_class\\\">$s</span>\"",
";",
"}",
"return",
"$",
"buffer",
";",
"}",
"}"
] | Process the validation errors and return human readable error messages.
@param bool $convert_to_string = false
@param string $field_class
@param string $error_class
@return array
@return string | [
"Process",
"the",
"validation",
"errors",
"and",
"return",
"human",
"readable",
"error",
"messages",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L559-L605 | train |
Wixel/GUMP | gump.class.php | GUMP.get_errors_array | public function get_errors_array($convert_to_string = null)
{
if (empty($this->errors)) {
return ($convert_to_string) ? null : array();
}
$resp = array();
// Error messages
$messages = $this->get_messages();
foreach ($this->errors as $e)
{
$field = ucwords(str_replace(array('_', '-'), chr(32), $e['field']));
$param = $e['param'];
// Let's fetch explicitly if the field names exist
if (array_key_exists($e['field'], self::$fields)) {
$field = self::$fields[$e['field']];
// If param is a field (i.e. equalsfield validator)
if (array_key_exists($param, self::$fields)) {
$param = self::$fields[$e['param']];
}
}
// Messages
if (isset($messages[$e['rule']])) {
// Show first validation error and don't allow to be overwritten
if (!isset($resp[$e['field']])) {
if (is_array($param)) {
$param = implode(', ', $param);
}
$message = str_replace('{param}', $param, str_replace('{field}', $field, $messages[$e['rule']]));
$resp[$e['field']] = $message;
}
} else {
throw new \Exception ('Rule "'.$e['rule'].'" does not have an error message');
}
}
return $resp;
} | php | public function get_errors_array($convert_to_string = null)
{
if (empty($this->errors)) {
return ($convert_to_string) ? null : array();
}
$resp = array();
// Error messages
$messages = $this->get_messages();
foreach ($this->errors as $e)
{
$field = ucwords(str_replace(array('_', '-'), chr(32), $e['field']));
$param = $e['param'];
// Let's fetch explicitly if the field names exist
if (array_key_exists($e['field'], self::$fields)) {
$field = self::$fields[$e['field']];
// If param is a field (i.e. equalsfield validator)
if (array_key_exists($param, self::$fields)) {
$param = self::$fields[$e['param']];
}
}
// Messages
if (isset($messages[$e['rule']])) {
// Show first validation error and don't allow to be overwritten
if (!isset($resp[$e['field']])) {
if (is_array($param)) {
$param = implode(', ', $param);
}
$message = str_replace('{param}', $param, str_replace('{field}', $field, $messages[$e['rule']]));
$resp[$e['field']] = $message;
}
} else {
throw new \Exception ('Rule "'.$e['rule'].'" does not have an error message');
}
}
return $resp;
} | [
"public",
"function",
"get_errors_array",
"(",
"$",
"convert_to_string",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"errors",
")",
")",
"{",
"return",
"(",
"$",
"convert_to_string",
")",
"?",
"null",
":",
"array",
"(",
")",
";",
"}",
"$",
"resp",
"=",
"array",
"(",
")",
";",
"// Error messages",
"$",
"messages",
"=",
"$",
"this",
"->",
"get_messages",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"errors",
"as",
"$",
"e",
")",
"{",
"$",
"field",
"=",
"ucwords",
"(",
"str_replace",
"(",
"array",
"(",
"'_'",
",",
"'-'",
")",
",",
"chr",
"(",
"32",
")",
",",
"$",
"e",
"[",
"'field'",
"]",
")",
")",
";",
"$",
"param",
"=",
"$",
"e",
"[",
"'param'",
"]",
";",
"// Let's fetch explicitly if the field names exist",
"if",
"(",
"array_key_exists",
"(",
"$",
"e",
"[",
"'field'",
"]",
",",
"self",
"::",
"$",
"fields",
")",
")",
"{",
"$",
"field",
"=",
"self",
"::",
"$",
"fields",
"[",
"$",
"e",
"[",
"'field'",
"]",
"]",
";",
"// If param is a field (i.e. equalsfield validator)",
"if",
"(",
"array_key_exists",
"(",
"$",
"param",
",",
"self",
"::",
"$",
"fields",
")",
")",
"{",
"$",
"param",
"=",
"self",
"::",
"$",
"fields",
"[",
"$",
"e",
"[",
"'param'",
"]",
"]",
";",
"}",
"}",
"// Messages",
"if",
"(",
"isset",
"(",
"$",
"messages",
"[",
"$",
"e",
"[",
"'rule'",
"]",
"]",
")",
")",
"{",
"// Show first validation error and don't allow to be overwritten",
"if",
"(",
"!",
"isset",
"(",
"$",
"resp",
"[",
"$",
"e",
"[",
"'field'",
"]",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"param",
")",
")",
"{",
"$",
"param",
"=",
"implode",
"(",
"', '",
",",
"$",
"param",
")",
";",
"}",
"$",
"message",
"=",
"str_replace",
"(",
"'{param}'",
",",
"$",
"param",
",",
"str_replace",
"(",
"'{field}'",
",",
"$",
"field",
",",
"$",
"messages",
"[",
"$",
"e",
"[",
"'rule'",
"]",
"]",
")",
")",
";",
"$",
"resp",
"[",
"$",
"e",
"[",
"'field'",
"]",
"]",
"=",
"$",
"message",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Rule \"'",
".",
"$",
"e",
"[",
"'rule'",
"]",
".",
"'\" does not have an error message'",
")",
";",
"}",
"}",
"return",
"$",
"resp",
";",
"}"
] | Process the validation errors and return an array of errors with field names as keys.
@param $convert_to_string
@return array | null (if empty) | [
"Process",
"the",
"validation",
"errors",
"and",
"return",
"an",
"array",
"of",
"errors",
"with",
"field",
"names",
"as",
"keys",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L614-L656 | train |
Wixel/GUMP | gump.class.php | GUMP.filter_slug | protected function filter_slug($value, $params = null)
{
$delimiter = '-';
$slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter));
return $slug;
} | php | protected function filter_slug($value, $params = null)
{
$delimiter = '-';
$slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter));
return $slug;
} | [
"protected",
"function",
"filter_slug",
"(",
"$",
"value",
",",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"delimiter",
"=",
"'-'",
";",
"$",
"slug",
"=",
"strtolower",
"(",
"trim",
"(",
"preg_replace",
"(",
"'/[\\s-]+/'",
",",
"$",
"delimiter",
",",
"preg_replace",
"(",
"'/[^A-Za-z0-9-]+/'",
",",
"$",
"delimiter",
",",
"preg_replace",
"(",
"'/[&]/'",
",",
"'and'",
",",
"preg_replace",
"(",
"'/[\\']/'",
",",
"''",
",",
"iconv",
"(",
"'UTF-8'",
",",
"'ASCII//TRANSLIT'",
",",
"$",
"str",
")",
")",
")",
")",
")",
",",
"$",
"delimiter",
")",
")",
";",
"return",
"$",
"slug",
";",
"}"
] | Converts value to url-web-slugs.
Credit:
https://stackoverflow.com/questions/40641973/php-to-convert-string-to-slug
http://cubiq.org/the-perfect-php-clean-url-generator
@param string $value
@param array $params
@return string | [
"Converts",
"value",
"to",
"url",
"-",
"web",
"-",
"slugs",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L951-L956 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_contains | protected function validate_contains($field, $input, $param = null)
{
if (!isset($input[$field])) {
return;
}
$param = trim(strtolower($param));
$value = trim(strtolower($input[$field]));
if (preg_match_all('#\'(.+?)\'#', $param, $matches, PREG_PATTERN_ORDER)) {
$param = $matches[1];
} else {
$param = explode(chr(32), $param);
}
if (in_array($value, $param)) { // valid, return nothing
return;
}
return array(
'field' => $field,
'value' => $value,
'rule' => __FUNCTION__,
'param' => $param,
);
} | php | protected function validate_contains($field, $input, $param = null)
{
if (!isset($input[$field])) {
return;
}
$param = trim(strtolower($param));
$value = trim(strtolower($input[$field]));
if (preg_match_all('#\'(.+?)\'#', $param, $matches, PREG_PATTERN_ORDER)) {
$param = $matches[1];
} else {
$param = explode(chr(32), $param);
}
if (in_array($value, $param)) { // valid, return nothing
return;
}
return array(
'field' => $field,
'value' => $value,
'rule' => __FUNCTION__,
'param' => $param,
);
} | [
"protected",
"function",
"validate_contains",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"param",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"param",
")",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
";",
"if",
"(",
"preg_match_all",
"(",
"'#\\'(.+?)\\'#'",
",",
"$",
"param",
",",
"$",
"matches",
",",
"PREG_PATTERN_ORDER",
")",
")",
"{",
"$",
"param",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"param",
"=",
"explode",
"(",
"chr",
"(",
"32",
")",
",",
"$",
"param",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"param",
")",
")",
"{",
"// valid, return nothing",
"return",
";",
"}",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"value",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}"
] | Verify that a value is contained within the pre-defined value set.
Usage: '<index>' => 'contains,value value value'
@param string $field
@param array $input
@param null $param
@return mixed | [
"Verify",
"that",
"a",
"value",
"is",
"contained",
"within",
"the",
"pre",
"-",
"defined",
"value",
"set",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L972-L998 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_required | protected function validate_required($field, $input, $param = null)
{
if (isset($input[$field]) && ($input[$field] === false || $input[$field] === 0 || $input[$field] === 0.0 || $input[$field] === '0' || !empty($input[$field]))) {
return;
}
return array(
'field' => $field,
'value' => null,
'rule' => __FUNCTION__,
'param' => $param,
);
} | php | protected function validate_required($field, $input, $param = null)
{
if (isset($input[$field]) && ($input[$field] === false || $input[$field] === 0 || $input[$field] === 0.0 || $input[$field] === '0' || !empty($input[$field]))) {
return;
}
return array(
'field' => $field,
'value' => null,
'rule' => __FUNCTION__,
'param' => $param,
);
} | [
"protected",
"function",
"validate_required",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"&&",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
"===",
"false",
"||",
"$",
"input",
"[",
"$",
"field",
"]",
"===",
"0",
"||",
"$",
"input",
"[",
"$",
"field",
"]",
"===",
"0.0",
"||",
"$",
"input",
"[",
"$",
"field",
"]",
"===",
"'0'",
"||",
"!",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
")",
"{",
"return",
";",
"}",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"null",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}"
] | Check if the specified key is present and not empty.
Usage: '<index>' => 'required'
@param string $field
@param array $input
@param null $param
@return mixed | [
"Check",
"if",
"the",
"specified",
"key",
"is",
"present",
"and",
"not",
"empty",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1083-L1095 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_valid_email | protected function validate_valid_email($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!filter_var($input[$field], FILTER_VALIDATE_EMAIL)) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_valid_email($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!filter_var($input[$field], FILTER_VALIDATE_EMAIL)) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_valid_email",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"FILTER_VALIDATE_EMAIL",
")",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Determine if the provided email is valid.
Usage: '<index>' => 'valid_email'
@param string $field
@param array $input
@param null $param
@return mixed | [
"Determine",
"if",
"the",
"provided",
"email",
"is",
"valid",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1108-L1122 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_max_len | protected function validate_max_len($field, $input, $param = null)
{
if (!isset($input[$field])) {
return;
}
if (function_exists('mb_strlen')) {
if (mb_strlen($input[$field]) <= (int) $param) {
return;
}
} else {
if (strlen($input[$field]) <= (int) $param) {
return;
}
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
} | php | protected function validate_max_len($field, $input, $param = null)
{
if (!isset($input[$field])) {
return;
}
if (function_exists('mb_strlen')) {
if (mb_strlen($input[$field]) <= (int) $param) {
return;
}
} else {
if (strlen($input[$field]) <= (int) $param) {
return;
}
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
} | [
"protected",
"function",
"validate_max_len",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'mb_strlen'",
")",
")",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"<=",
"(",
"int",
")",
"$",
"param",
")",
"{",
"return",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"strlen",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"<=",
"(",
"int",
")",
"$",
"param",
")",
"{",
"return",
";",
"}",
"}",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}"
] | Determine if the provided value length is less or equal to a specific value.
Usage: '<index>' => 'max_len,240'
@param string $field
@param array $input
@param null $param
@return mixed | [
"Determine",
"if",
"the",
"provided",
"value",
"length",
"is",
"less",
"or",
"equal",
"to",
"a",
"specific",
"value",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1135-L1157 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_numeric | protected function validate_numeric($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!is_numeric($input[$field])) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_numeric($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!is_numeric($input[$field])) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_numeric",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Determine if the provided value is a valid number or numeric string.
Usage: '<index>' => 'numeric'
@param string $field
@param array $input
@param null $param
@return mixed | [
"Determine",
"if",
"the",
"provided",
"value",
"is",
"a",
"valid",
"number",
"or",
"numeric",
"string",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1375-L1389 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_valid_url | protected function validate_valid_url($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!filter_var($input[$field], FILTER_VALIDATE_URL)) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_valid_url($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!filter_var($input[$field], FILTER_VALIDATE_URL)) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_valid_url",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Determine if the provided value is a valid URL.
Usage: '<index>' => 'valid_url'
@param string $field
@param array $input
@param null $param
@return mixed | [
"Determine",
"if",
"the",
"provided",
"value",
"is",
"a",
"valid",
"URL",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1486-L1500 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_valid_ip | protected function validate_valid_ip($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!filter_var($input[$field], FILTER_VALIDATE_IP) !== false) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_valid_ip($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!filter_var($input[$field], FILTER_VALIDATE_IP) !== false) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_valid_ip",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"FILTER_VALIDATE_IP",
")",
"!==",
"false",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Determine if the provided value is a valid IP address.
Usage: '<index>' => 'valid_ip'
@param string $field
@param array $input
@return mixed | [
"Determine",
"if",
"the",
"provided",
"value",
"is",
"a",
"valid",
"IP",
"address",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1556-L1570 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_valid_ipv6 | protected function validate_valid_ipv6($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!filter_var($input[$field], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_valid_ipv6($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!filter_var($input[$field], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_valid_ipv6",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV6",
")",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Determine if the provided value is a valid IPv6 address.
Usage: '<index>' => 'valid_ipv6'
@param string $field
@param array $input
@return mixed | [
"Determine",
"if",
"the",
"provided",
"value",
"is",
"a",
"valid",
"IPv6",
"address",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1617-L1631 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_valid_cc | protected function validate_valid_cc($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
$number = preg_replace('/\D/', '', $input[$field]);
if (function_exists('mb_strlen')) {
$number_length = mb_strlen($number);
} else {
$number_length = strlen($number);
}
/**
* Bail out if $number_length is 0.
* This can be the case if a user has entered only alphabets
*
* @since 1.5
*/
if( $number_length == 0 ) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
$parity = $number_length % 2;
$total = 0;
for ($i = 0; $i < $number_length; ++$i) {
$digit = $number[$i];
if ($i % 2 == $parity) {
$digit *= 2;
if ($digit > 9) {
$digit -= 9;
}
}
$total += $digit;
}
if ($total % 10 == 0) {
return; // Valid
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
} | php | protected function validate_valid_cc($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
$number = preg_replace('/\D/', '', $input[$field]);
if (function_exists('mb_strlen')) {
$number_length = mb_strlen($number);
} else {
$number_length = strlen($number);
}
/**
* Bail out if $number_length is 0.
* This can be the case if a user has entered only alphabets
*
* @since 1.5
*/
if( $number_length == 0 ) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
$parity = $number_length % 2;
$total = 0;
for ($i = 0; $i < $number_length; ++$i) {
$digit = $number[$i];
if ($i % 2 == $parity) {
$digit *= 2;
if ($digit > 9) {
$digit -= 9;
}
}
$total += $digit;
}
if ($total % 10 == 0) {
return; // Valid
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
} | [
"protected",
"function",
"validate_valid_cc",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"number",
"=",
"preg_replace",
"(",
"'/\\D/'",
",",
"''",
",",
"$",
"input",
"[",
"$",
"field",
"]",
")",
";",
"if",
"(",
"function_exists",
"(",
"'mb_strlen'",
")",
")",
"{",
"$",
"number_length",
"=",
"mb_strlen",
"(",
"$",
"number",
")",
";",
"}",
"else",
"{",
"$",
"number_length",
"=",
"strlen",
"(",
"$",
"number",
")",
";",
"}",
"/**\n * Bail out if $number_length is 0. \n * This can be the case if a user has entered only alphabets\n * \n * @since 1.5\n */",
"if",
"(",
"$",
"number_length",
"==",
"0",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"$",
"parity",
"=",
"$",
"number_length",
"%",
"2",
";",
"$",
"total",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"number_length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"digit",
"=",
"$",
"number",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"i",
"%",
"2",
"==",
"$",
"parity",
")",
"{",
"$",
"digit",
"*=",
"2",
";",
"if",
"(",
"$",
"digit",
">",
"9",
")",
"{",
"$",
"digit",
"-=",
"9",
";",
"}",
"}",
"$",
"total",
"+=",
"$",
"digit",
";",
"}",
"if",
"(",
"$",
"total",
"%",
"10",
"==",
"0",
")",
"{",
"return",
";",
"// Valid",
"}",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}"
] | Determine if the input is a valid credit card number.
See: http://stackoverflow.com/questions/174730/what-is-the-best-way-to-validate-a-credit-card-in-php
Usage: '<index>' => 'valid_cc'
@param string $field
@param array $input
@return mixed | [
"Determine",
"if",
"the",
"input",
"is",
"a",
"valid",
"credit",
"card",
"number",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1644-L1703 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_street_address | protected function validate_street_address($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
// Theory: 1 number, 1 or more spaces, 1 or more words
$hasLetter = preg_match('/[a-zA-Z]/', $input[$field]);
$hasDigit = preg_match('/\d/', $input[$field]);
$hasSpace = preg_match('/\s/', $input[$field]);
$passes = $hasLetter && $hasDigit && $hasSpace;
if (!$passes) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_street_address($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
// Theory: 1 number, 1 or more spaces, 1 or more words
$hasLetter = preg_match('/[a-zA-Z]/', $input[$field]);
$hasDigit = preg_match('/\d/', $input[$field]);
$hasSpace = preg_match('/\s/', $input[$field]);
$passes = $hasLetter && $hasDigit && $hasSpace;
if (!$passes) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_street_address",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"// Theory: 1 number, 1 or more spaces, 1 or more words",
"$",
"hasLetter",
"=",
"preg_match",
"(",
"'/[a-zA-Z]/'",
",",
"$",
"input",
"[",
"$",
"field",
"]",
")",
";",
"$",
"hasDigit",
"=",
"preg_match",
"(",
"'/\\d/'",
",",
"$",
"input",
"[",
"$",
"field",
"]",
")",
";",
"$",
"hasSpace",
"=",
"preg_match",
"(",
"'/\\s/'",
",",
"$",
"input",
"[",
"$",
"field",
"]",
")",
";",
"$",
"passes",
"=",
"$",
"hasLetter",
"&&",
"$",
"hasDigit",
"&&",
"$",
"hasSpace",
";",
"if",
"(",
"!",
"$",
"passes",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Determine if the provided input is likely to be a street address using weak detection.
Usage: '<index>' => 'street_address'
@param string $field
@param array $input
@return mixed | [
"Determine",
"if",
"the",
"provided",
"input",
"is",
"likely",
"to",
"be",
"a",
"street",
"address",
"using",
"weak",
"detection",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1742-L1763 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_starts | protected function validate_starts($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (strpos($input[$field], $param) !== 0) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_starts($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (strpos($input[$field], $param) !== 0) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_starts",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"$",
"param",
")",
"!==",
"0",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Determine if the provided value starts with param.
Usage: '<index>' => 'starts,Z'
@param string $field
@param array $input
@return mixed | [
"Determine",
"if",
"the",
"provided",
"value",
"starts",
"with",
"param",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1960-L1974 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_required_file | protected function validate_required_file($field, $input, $param = null)
{
if (!isset($input[$field])) {
return;
}
if (is_array($input[$field]) && $input[$field]['error'] !== 4) {
return;
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
} | php | protected function validate_required_file($field, $input, $param = null)
{
if (!isset($input[$field])) {
return;
}
if (is_array($input[$field]) && $input[$field]['error'] !== 4) {
return;
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
} | [
"protected",
"function",
"validate_required_file",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"&&",
"$",
"input",
"[",
"$",
"field",
"]",
"[",
"'error'",
"]",
"!==",
"4",
")",
"{",
"return",
";",
"}",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}"
] | Checks if a file was uploaded.
Usage: '<index>' => 'required_file'
@param string $field
@param array $input
@return mixed | [
"Checks",
"if",
"a",
"file",
"was",
"uploaded",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L1986-L2002 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_extension | protected function validate_extension($field, $input, $param = null)
{
if (!isset($input[$field])) {
return;
}
if (is_array($input[$field]) && $input[$field]['error'] !== 4) {
$param = trim(strtolower($param));
$allowed_extensions = explode(';', $param);
$path_info = pathinfo($input[$field]['name']);
$extension = isset($path_info['extension']) ? $path_info['extension'] : false;
if ($extension && in_array(strtolower($extension), $allowed_extensions)) {
return;
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_extension($field, $input, $param = null)
{
if (!isset($input[$field])) {
return;
}
if (is_array($input[$field]) && $input[$field]['error'] !== 4) {
$param = trim(strtolower($param));
$allowed_extensions = explode(';', $param);
$path_info = pathinfo($input[$field]['name']);
$extension = isset($path_info['extension']) ? $path_info['extension'] : false;
if ($extension && in_array(strtolower($extension), $allowed_extensions)) {
return;
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_extension",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"&&",
"$",
"input",
"[",
"$",
"field",
"]",
"[",
"'error'",
"]",
"!==",
"4",
")",
"{",
"$",
"param",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"param",
")",
")",
";",
"$",
"allowed_extensions",
"=",
"explode",
"(",
"';'",
",",
"$",
"param",
")",
";",
"$",
"path_info",
"=",
"pathinfo",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
"[",
"'name'",
"]",
")",
";",
"$",
"extension",
"=",
"isset",
"(",
"$",
"path_info",
"[",
"'extension'",
"]",
")",
"?",
"$",
"path_info",
"[",
"'extension'",
"]",
":",
"false",
";",
"if",
"(",
"$",
"extension",
"&&",
"in_array",
"(",
"strtolower",
"(",
"$",
"extension",
")",
",",
"$",
"allowed_extensions",
")",
")",
"{",
"return",
";",
"}",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Check the uploaded file for extension for now
checks only the ext should add mime type check.
Usage: '<index>' => 'extension,png;jpg;gif
@param string $field
@param array $input
@return mixed | [
"Check",
"the",
"uploaded",
"file",
"for",
"extension",
"for",
"now",
"checks",
"only",
"the",
"ext",
"should",
"add",
"mime",
"type",
"check",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L2015-L2039 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_equalsfield | protected function validate_equalsfield($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if ($input[$field] == $input[$param]) {
return;
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
} | php | protected function validate_equalsfield($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if ($input[$field] == $input[$param]) {
return;
}
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
} | [
"protected",
"function",
"validate_equalsfield",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
"==",
"$",
"input",
"[",
"$",
"param",
"]",
")",
"{",
"return",
";",
"}",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}"
] | Determine if the provided field value equals current field value.
Usage: '<index>' => 'equalsfield,Z'
@param string $field
@param string $input
@param string $param field to compare with
@return mixed | [
"Determine",
"if",
"the",
"provided",
"field",
"value",
"equals",
"current",
"field",
"value",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L2053-L2069 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_phone_number | protected function validate_phone_number($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
$regex = '/^(\d[\s-\.]?)?[\(\[\s-\.]{0,2}?\d{3}[\)\]\s-\.]{0,2}?\d{3}[\s-\.]?\d{4}$/i';
if (!preg_match($regex, $input[$field])) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_phone_number($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
$regex = '/^(\d[\s-\.]?)?[\(\[\s-\.]{0,2}?\d{3}[\)\]\s-\.]{0,2}?\d{3}[\s-\.]?\d{4}$/i';
if (!preg_match($regex, $input[$field])) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_phone_number",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"regex",
"=",
"'/^(\\d[\\s-\\.]?)?[\\(\\[\\s-\\.]{0,2}?\\d{3}[\\)\\]\\s-\\.]{0,2}?\\d{3}[\\s-\\.]?\\d{4}$/i'",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Determine if the provided value is a valid phone number.
Usage: '<index>' => 'phone_number'
@param string $field
@param array $input
@return mixed
Examples:
555-555-5555: valid
555.555.5555: valid
5555425555: valid
555 555 5555: valid
1(519) 555-4444: valid
1 (519) 555-4422: valid
1-555-555-5555: valid
1-(555)-555-5555: valid | [
"Determine",
"if",
"the",
"provided",
"value",
"is",
"a",
"valid",
"phone",
"number",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L2136-L2151 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_valid_json_string | protected function validate_valid_json_string($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!is_string($input[$field]) || !is_object(json_decode($input[$field]))) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_valid_json_string($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!is_string($input[$field]) || !is_object(json_decode($input[$field]))) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_valid_json_string",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"!",
"is_object",
"(",
"json_decode",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | JSON validator.
Usage: '<index>' => 'valid_json_string'
@param string $field
@param array $input
@return mixed | [
"JSON",
"validator",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L2190-L2204 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_valid_array_size_greater | protected function validate_valid_array_size_greater($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!is_array($input[$field]) || sizeof($input[$field]) < (int)$param) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | php | protected function validate_valid_array_size_greater($field, $input, $param = null)
{
if (!isset($input[$field]) || empty($input[$field])) {
return;
}
if (!is_array($input[$field]) || sizeof($input[$field]) < (int)$param) {
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param,
);
}
} | [
"protected",
"function",
"validate_valid_array_size_greater",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"sizeof",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"<",
"(",
"int",
")",
"$",
"param",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
",",
")",
";",
"}",
"}"
] | Check if an input is an array and if the size is more or equal to a specific value.
Usage: '<index>' => 'valid_array_size_greater,1'
@param string $field
@param array $input
@return mixed | [
"Check",
"if",
"an",
"input",
"is",
"an",
"array",
"and",
"if",
"the",
"size",
"is",
"more",
"or",
"equal",
"to",
"a",
"specific",
"value",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L2216-L2230 | train |
Wixel/GUMP | gump.class.php | GUMP.validate_valid_twitter | protected function validate_valid_twitter($field, $input, $param = NULL)
{
if(!isset($input[$field]) || empty($input[$field]))
{
return;
}
$json_twitter = file_get_contents("http://twitter.com/users/username_available?username=".$input[$field]);
$twitter_response = json_decode($json_twitter);
if($twitter_response->reason != "taken"){
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param
);
}
} | php | protected function validate_valid_twitter($field, $input, $param = NULL)
{
if(!isset($input[$field]) || empty($input[$field]))
{
return;
}
$json_twitter = file_get_contents("http://twitter.com/users/username_available?username=".$input[$field]);
$twitter_response = json_decode($json_twitter);
if($twitter_response->reason != "taken"){
return array(
'field' => $field,
'value' => $input[$field],
'rule' => __FUNCTION__,
'param' => $param
);
}
} | [
"protected",
"function",
"validate_valid_twitter",
"(",
"$",
"field",
",",
"$",
"input",
",",
"$",
"param",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"json_twitter",
"=",
"file_get_contents",
"(",
"\"http://twitter.com/users/username_available?username=\"",
".",
"$",
"input",
"[",
"$",
"field",
"]",
")",
";",
"$",
"twitter_response",
"=",
"json_decode",
"(",
"$",
"json_twitter",
")",
";",
"if",
"(",
"$",
"twitter_response",
"->",
"reason",
"!=",
"\"taken\"",
")",
"{",
"return",
"array",
"(",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"'rule'",
"=>",
"__FUNCTION__",
",",
"'param'",
"=>",
"$",
"param",
")",
";",
"}",
"}"
] | Determine if the provided value is a valid twitter handle.
@access protected
@param string $field
@param array $input
@return mixed | [
"Determine",
"if",
"the",
"provided",
"value",
"is",
"a",
"valid",
"twitter",
"handle",
"."
] | 6f7451eddcdca596495ce6883855e9c59d35e1e6 | https://github.com/Wixel/GUMP/blob/6f7451eddcdca596495ce6883855e9c59d35e1e6/gump.class.php#L2425-L2442 | train |
thephpleague/glide | src/Manipulators/Sharpen.php | Sharpen.run | public function run(Image $image)
{
$sharpen = $this->getSharpen();
if ($sharpen !== null) {
$image->sharpen($sharpen);
}
return $image;
} | php | public function run(Image $image)
{
$sharpen = $this->getSharpen();
if ($sharpen !== null) {
$image->sharpen($sharpen);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"sharpen",
"=",
"$",
"this",
"->",
"getSharpen",
"(",
")",
";",
"if",
"(",
"$",
"sharpen",
"!==",
"null",
")",
"{",
"$",
"image",
"->",
"sharpen",
"(",
"$",
"sharpen",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform sharpen image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"sharpen",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Sharpen.php#L17-L26 | train |
thephpleague/glide | src/Manipulators/Sharpen.php | Sharpen.getSharpen | public function getSharpen()
{
if (!is_numeric($this->sharp)) {
return;
}
if ($this->sharp < 0 or $this->sharp > 100) {
return;
}
return (int) $this->sharp;
} | php | public function getSharpen()
{
if (!is_numeric($this->sharp)) {
return;
}
if ($this->sharp < 0 or $this->sharp > 100) {
return;
}
return (int) $this->sharp;
} | [
"public",
"function",
"getSharpen",
"(",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"sharp",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"sharp",
"<",
"0",
"or",
"$",
"this",
"->",
"sharp",
">",
"100",
")",
"{",
"return",
";",
"}",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"sharp",
";",
"}"
] | Resolve sharpen amount.
@return string The resolved sharpen amount. | [
"Resolve",
"sharpen",
"amount",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Sharpen.php#L32-L43 | train |
thephpleague/glide | src/Manipulators/Filter.php | Filter.run | public function run(Image $image)
{
if ($this->filt === 'greyscale') {
return $this->runGreyscaleFilter($image);
}
if ($this->filt === 'sepia') {
return $this->runSepiaFilter($image);
}
return $image;
} | php | public function run(Image $image)
{
if ($this->filt === 'greyscale') {
return $this->runGreyscaleFilter($image);
}
if ($this->filt === 'sepia') {
return $this->runSepiaFilter($image);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"filt",
"===",
"'greyscale'",
")",
"{",
"return",
"$",
"this",
"->",
"runGreyscaleFilter",
"(",
"$",
"image",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"filt",
"===",
"'sepia'",
")",
"{",
"return",
"$",
"this",
"->",
"runSepiaFilter",
"(",
"$",
"image",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform filter image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"filter",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Filter.php#L17-L28 | train |
thephpleague/glide | src/Manipulators/Filter.php | Filter.runSepiaFilter | public function runSepiaFilter(Image $image)
{
$image->greyscale();
$image->brightness(-10);
$image->contrast(10);
$image->colorize(38, 27, 12);
$image->brightness(-10);
$image->contrast(10);
return $image;
} | php | public function runSepiaFilter(Image $image)
{
$image->greyscale();
$image->brightness(-10);
$image->contrast(10);
$image->colorize(38, 27, 12);
$image->brightness(-10);
$image->contrast(10);
return $image;
} | [
"public",
"function",
"runSepiaFilter",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"image",
"->",
"greyscale",
"(",
")",
";",
"$",
"image",
"->",
"brightness",
"(",
"-",
"10",
")",
";",
"$",
"image",
"->",
"contrast",
"(",
"10",
")",
";",
"$",
"image",
"->",
"colorize",
"(",
"38",
",",
"27",
",",
"12",
")",
";",
"$",
"image",
"->",
"brightness",
"(",
"-",
"10",
")",
";",
"$",
"image",
"->",
"contrast",
"(",
"10",
")",
";",
"return",
"$",
"image",
";",
"}"
] | Perform sepia manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"sepia",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Filter.php#L45-L55 | train |
thephpleague/glide | src/Manipulators/Contrast.php | Contrast.run | public function run(Image $image)
{
$contrast = $this->getContrast();
if ($contrast !== null) {
$image->contrast($contrast);
}
return $image;
} | php | public function run(Image $image)
{
$contrast = $this->getContrast();
if ($contrast !== null) {
$image->contrast($contrast);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"contrast",
"=",
"$",
"this",
"->",
"getContrast",
"(",
")",
";",
"if",
"(",
"$",
"contrast",
"!==",
"null",
")",
"{",
"$",
"image",
"->",
"contrast",
"(",
"$",
"contrast",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform contrast image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"contrast",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Contrast.php#L17-L26 | train |
thephpleague/glide | src/Manipulators/Contrast.php | Contrast.getContrast | public function getContrast()
{
if (!preg_match('/^-*[0-9]+$/', $this->con)) {
return;
}
if ($this->con < -100 or $this->con > 100) {
return;
}
return (int) $this->con;
} | php | public function getContrast()
{
if (!preg_match('/^-*[0-9]+$/', $this->con)) {
return;
}
if ($this->con < -100 or $this->con > 100) {
return;
}
return (int) $this->con;
} | [
"public",
"function",
"getContrast",
"(",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^-*[0-9]+$/'",
",",
"$",
"this",
"->",
"con",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"con",
"<",
"-",
"100",
"or",
"$",
"this",
"->",
"con",
">",
"100",
")",
"{",
"return",
";",
"}",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"con",
";",
"}"
] | Resolve contrast amount.
@return string The resolved contrast amount. | [
"Resolve",
"contrast",
"amount",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Contrast.php#L32-L43 | train |
thephpleague/glide | src/ServerFactory.php | ServerFactory.getSource | public function getSource()
{
if (!isset($this->config['source'])) {
throw new InvalidArgumentException('A "source" file system must be set.');
}
if (is_string($this->config['source'])) {
return new Filesystem(
new Local($this->config['source'])
);
}
return $this->config['source'];
} | php | public function getSource()
{
if (!isset($this->config['source'])) {
throw new InvalidArgumentException('A "source" file system must be set.');
}
if (is_string($this->config['source'])) {
return new Filesystem(
new Local($this->config['source'])
);
}
return $this->config['source'];
} | [
"public",
"function",
"getSource",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'source'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'A \"source\" file system must be set.'",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"config",
"[",
"'source'",
"]",
")",
")",
"{",
"return",
"new",
"Filesystem",
"(",
"new",
"Local",
"(",
"$",
"this",
"->",
"config",
"[",
"'source'",
"]",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"config",
"[",
"'source'",
"]",
";",
"}"
] | Get source file system.
@return FilesystemInterface Source file system. | [
"Get",
"source",
"file",
"system",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/ServerFactory.php#L73-L86 | train |
thephpleague/glide | src/ServerFactory.php | ServerFactory.getCache | public function getCache()
{
if (!isset($this->config['cache'])) {
throw new InvalidArgumentException('A "cache" file system must be set.');
}
if (is_string($this->config['cache'])) {
return new Filesystem(
new Local($this->config['cache'])
);
}
return $this->config['cache'];
} | php | public function getCache()
{
if (!isset($this->config['cache'])) {
throw new InvalidArgumentException('A "cache" file system must be set.');
}
if (is_string($this->config['cache'])) {
return new Filesystem(
new Local($this->config['cache'])
);
}
return $this->config['cache'];
} | [
"public",
"function",
"getCache",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'cache'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'A \"cache\" file system must be set.'",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"config",
"[",
"'cache'",
"]",
")",
")",
"{",
"return",
"new",
"Filesystem",
"(",
"new",
"Local",
"(",
"$",
"this",
"->",
"config",
"[",
"'cache'",
"]",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"config",
"[",
"'cache'",
"]",
";",
"}"
] | Get cache file system.
@return FilesystemInterface Cache file system. | [
"Get",
"cache",
"file",
"system",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/ServerFactory.php#L103-L116 | train |
thephpleague/glide | src/ServerFactory.php | ServerFactory.getWatermarks | public function getWatermarks()
{
if (!isset($this->config['watermarks'])) {
return;
}
if (is_string($this->config['watermarks'])) {
return new Filesystem(
new Local($this->config['watermarks'])
);
}
return $this->config['watermarks'];
} | php | public function getWatermarks()
{
if (!isset($this->config['watermarks'])) {
return;
}
if (is_string($this->config['watermarks'])) {
return new Filesystem(
new Local($this->config['watermarks'])
);
}
return $this->config['watermarks'];
} | [
"public",
"function",
"getWatermarks",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'watermarks'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"config",
"[",
"'watermarks'",
"]",
")",
")",
"{",
"return",
"new",
"Filesystem",
"(",
"new",
"Local",
"(",
"$",
"this",
"->",
"config",
"[",
"'watermarks'",
"]",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"config",
"[",
"'watermarks'",
"]",
";",
"}"
] | Get watermarks file system.
@return FilesystemInterface|null Watermarks file system. | [
"Get",
"watermarks",
"file",
"system",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/ServerFactory.php#L159-L172 | train |
thephpleague/glide | src/ServerFactory.php | ServerFactory.getImageManager | public function getImageManager()
{
$driver = 'gd';
if (isset($this->config['driver'])) {
$driver = $this->config['driver'];
}
return new ImageManager([
'driver' => $driver,
]);
} | php | public function getImageManager()
{
$driver = 'gd';
if (isset($this->config['driver'])) {
$driver = $this->config['driver'];
}
return new ImageManager([
'driver' => $driver,
]);
} | [
"public",
"function",
"getImageManager",
"(",
")",
"{",
"$",
"driver",
"=",
"'gd'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'driver'",
"]",
")",
")",
"{",
"$",
"driver",
"=",
"$",
"this",
"->",
"config",
"[",
"'driver'",
"]",
";",
"}",
"return",
"new",
"ImageManager",
"(",
"[",
"'driver'",
"=>",
"$",
"driver",
",",
"]",
")",
";",
"}"
] | Get Intervention image manager.
@return ImageManager Intervention image manager. | [
"Get",
"Intervention",
"image",
"manager",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/ServerFactory.php#L201-L212 | train |
thephpleague/glide | src/ServerFactory.php | ServerFactory.getManipulators | public function getManipulators()
{
return [
new Orientation(),
new Crop(),
new Size($this->getMaxImageSize()),
new Brightness(),
new Contrast(),
new Gamma(),
new Sharpen(),
new Filter(),
new Flip(),
new Blur(),
new Pixelate(),
new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix()),
new Background(),
new Border(),
new Encode(),
];
} | php | public function getManipulators()
{
return [
new Orientation(),
new Crop(),
new Size($this->getMaxImageSize()),
new Brightness(),
new Contrast(),
new Gamma(),
new Sharpen(),
new Filter(),
new Flip(),
new Blur(),
new Pixelate(),
new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix()),
new Background(),
new Border(),
new Encode(),
];
} | [
"public",
"function",
"getManipulators",
"(",
")",
"{",
"return",
"[",
"new",
"Orientation",
"(",
")",
",",
"new",
"Crop",
"(",
")",
",",
"new",
"Size",
"(",
"$",
"this",
"->",
"getMaxImageSize",
"(",
")",
")",
",",
"new",
"Brightness",
"(",
")",
",",
"new",
"Contrast",
"(",
")",
",",
"new",
"Gamma",
"(",
")",
",",
"new",
"Sharpen",
"(",
")",
",",
"new",
"Filter",
"(",
")",
",",
"new",
"Flip",
"(",
")",
",",
"new",
"Blur",
"(",
")",
",",
"new",
"Pixelate",
"(",
")",
",",
"new",
"Watermark",
"(",
"$",
"this",
"->",
"getWatermarks",
"(",
")",
",",
"$",
"this",
"->",
"getWatermarksPathPrefix",
"(",
")",
")",
",",
"new",
"Background",
"(",
")",
",",
"new",
"Border",
"(",
")",
",",
"new",
"Encode",
"(",
")",
",",
"]",
";",
"}"
] | Get image manipulators.
@return array Image manipulators. | [
"Get",
"image",
"manipulators",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/ServerFactory.php#L218-L237 | train |
thephpleague/glide | src/Manipulators/Blur.php | Blur.run | public function run(Image $image)
{
$blur = $this->getBlur();
if ($blur !== null) {
$image->blur($blur);
}
return $image;
} | php | public function run(Image $image)
{
$blur = $this->getBlur();
if ($blur !== null) {
$image->blur($blur);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"blur",
"=",
"$",
"this",
"->",
"getBlur",
"(",
")",
";",
"if",
"(",
"$",
"blur",
"!==",
"null",
")",
"{",
"$",
"image",
"->",
"blur",
"(",
"$",
"blur",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform blur image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"blur",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Blur.php#L17-L26 | train |
thephpleague/glide | src/Manipulators/Blur.php | Blur.getBlur | public function getBlur()
{
if (!is_numeric($this->blur)) {
return;
}
if ($this->blur < 0 or $this->blur > 100) {
return;
}
return (int) $this->blur;
} | php | public function getBlur()
{
if (!is_numeric($this->blur)) {
return;
}
if ($this->blur < 0 or $this->blur > 100) {
return;
}
return (int) $this->blur;
} | [
"public",
"function",
"getBlur",
"(",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"blur",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"blur",
"<",
"0",
"or",
"$",
"this",
"->",
"blur",
">",
"100",
")",
"{",
"return",
";",
"}",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"blur",
";",
"}"
] | Resolve blur amount.
@return string The resolved blur amount. | [
"Resolve",
"blur",
"amount",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Blur.php#L32-L43 | train |
thephpleague/glide | src/Manipulators/Orientation.php | Orientation.run | public function run(Image $image)
{
$orientation = $this->getOrientation();
if ($orientation === 'auto') {
return $image->orientate();
}
return $image->rotate($orientation);
} | php | public function run(Image $image)
{
$orientation = $this->getOrientation();
if ($orientation === 'auto') {
return $image->orientate();
}
return $image->rotate($orientation);
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"orientation",
"=",
"$",
"this",
"->",
"getOrientation",
"(",
")",
";",
"if",
"(",
"$",
"orientation",
"===",
"'auto'",
")",
"{",
"return",
"$",
"image",
"->",
"orientate",
"(",
")",
";",
"}",
"return",
"$",
"image",
"->",
"rotate",
"(",
"$",
"orientation",
")",
";",
"}"
] | Perform orientation image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"orientation",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Orientation.php#L17-L26 | train |
thephpleague/glide | src/Manipulators/Encode.php | Encode.run | public function run(Image $image)
{
$format = $this->getFormat($image);
$quality = $this->getQuality();
if (in_array($format, ['jpg', 'pjpg'], true)) {
$image = $image->getDriver()
->newImage($image->width(), $image->height(), '#fff')
->insert($image, 'top-left', 0, 0);
}
if ($format === 'pjpg') {
$image->interlace();
$format = 'jpg';
}
return $image->encode($format, $quality);
} | php | public function run(Image $image)
{
$format = $this->getFormat($image);
$quality = $this->getQuality();
if (in_array($format, ['jpg', 'pjpg'], true)) {
$image = $image->getDriver()
->newImage($image->width(), $image->height(), '#fff')
->insert($image, 'top-left', 0, 0);
}
if ($format === 'pjpg') {
$image->interlace();
$format = 'jpg';
}
return $image->encode($format, $quality);
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"getFormat",
"(",
"$",
"image",
")",
";",
"$",
"quality",
"=",
"$",
"this",
"->",
"getQuality",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"format",
",",
"[",
"'jpg'",
",",
"'pjpg'",
"]",
",",
"true",
")",
")",
"{",
"$",
"image",
"=",
"$",
"image",
"->",
"getDriver",
"(",
")",
"->",
"newImage",
"(",
"$",
"image",
"->",
"width",
"(",
")",
",",
"$",
"image",
"->",
"height",
"(",
")",
",",
"'#fff'",
")",
"->",
"insert",
"(",
"$",
"image",
",",
"'top-left'",
",",
"0",
",",
"0",
")",
";",
"}",
"if",
"(",
"$",
"format",
"===",
"'pjpg'",
")",
"{",
"$",
"image",
"->",
"interlace",
"(",
")",
";",
"$",
"format",
"=",
"'jpg'",
";",
"}",
"return",
"$",
"image",
"->",
"encode",
"(",
"$",
"format",
",",
"$",
"quality",
")",
";",
"}"
] | Perform output image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"output",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Encode.php#L18-L35 | train |
thephpleague/glide | src/Manipulators/Encode.php | Encode.getFormat | public function getFormat(Image $image)
{
$allowed = [
'gif' => 'image/gif',
'jpg' => 'image/jpeg',
'pjpg' => 'image/jpeg',
'png' => 'image/png',
'webp' => 'image/webp',
];
if (array_key_exists($this->fm, $allowed)) {
return $this->fm;
}
if ($format = array_search($image->mime(), $allowed, true)) {
return $format;
}
return 'jpg';
} | php | public function getFormat(Image $image)
{
$allowed = [
'gif' => 'image/gif',
'jpg' => 'image/jpeg',
'pjpg' => 'image/jpeg',
'png' => 'image/png',
'webp' => 'image/webp',
];
if (array_key_exists($this->fm, $allowed)) {
return $this->fm;
}
if ($format = array_search($image->mime(), $allowed, true)) {
return $format;
}
return 'jpg';
} | [
"public",
"function",
"getFormat",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"allowed",
"=",
"[",
"'gif'",
"=>",
"'image/gif'",
",",
"'jpg'",
"=>",
"'image/jpeg'",
",",
"'pjpg'",
"=>",
"'image/jpeg'",
",",
"'png'",
"=>",
"'image/png'",
",",
"'webp'",
"=>",
"'image/webp'",
",",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"fm",
",",
"$",
"allowed",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fm",
";",
"}",
"if",
"(",
"$",
"format",
"=",
"array_search",
"(",
"$",
"image",
"->",
"mime",
"(",
")",
",",
"$",
"allowed",
",",
"true",
")",
")",
"{",
"return",
"$",
"format",
";",
"}",
"return",
"'jpg'",
";",
"}"
] | Resolve format.
@param Image $image The source image.
@return string The resolved format. | [
"Resolve",
"format",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Encode.php#L42-L61 | train |
thephpleague/glide | src/Manipulators/Encode.php | Encode.getQuality | public function getQuality()
{
$default = 90;
if (!is_numeric($this->q)) {
return $default;
}
if ($this->q < 0 or $this->q > 100) {
return $default;
}
return (int) $this->q;
} | php | public function getQuality()
{
$default = 90;
if (!is_numeric($this->q)) {
return $default;
}
if ($this->q < 0 or $this->q > 100) {
return $default;
}
return (int) $this->q;
} | [
"public",
"function",
"getQuality",
"(",
")",
"{",
"$",
"default",
"=",
"90",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"q",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"q",
"<",
"0",
"or",
"$",
"this",
"->",
"q",
">",
"100",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"q",
";",
"}"
] | Resolve quality.
@return string The resolved quality. | [
"Resolve",
"quality",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Encode.php#L67-L80 | train |
thephpleague/glide | src/Manipulators/Crop.php | Crop.run | public function run(Image $image)
{
$coordinates = $this->getCoordinates($image);
if ($coordinates) {
$coordinates = $this->limitToImageBoundaries($image, $coordinates);
$image->crop(
$coordinates[0],
$coordinates[1],
$coordinates[2],
$coordinates[3]
);
}
return $image;
} | php | public function run(Image $image)
{
$coordinates = $this->getCoordinates($image);
if ($coordinates) {
$coordinates = $this->limitToImageBoundaries($image, $coordinates);
$image->crop(
$coordinates[0],
$coordinates[1],
$coordinates[2],
$coordinates[3]
);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"coordinates",
"=",
"$",
"this",
"->",
"getCoordinates",
"(",
"$",
"image",
")",
";",
"if",
"(",
"$",
"coordinates",
")",
"{",
"$",
"coordinates",
"=",
"$",
"this",
"->",
"limitToImageBoundaries",
"(",
"$",
"image",
",",
"$",
"coordinates",
")",
";",
"$",
"image",
"->",
"crop",
"(",
"$",
"coordinates",
"[",
"0",
"]",
",",
"$",
"coordinates",
"[",
"1",
"]",
",",
"$",
"coordinates",
"[",
"2",
"]",
",",
"$",
"coordinates",
"[",
"3",
"]",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform crop image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"crop",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Crop.php#L17-L33 | train |
thephpleague/glide | src/Manipulators/Crop.php | Crop.getCoordinates | public function getCoordinates(Image $image)
{
$coordinates = explode(',', $this->crop);
if (count($coordinates) !== 4 or
(!is_numeric($coordinates[0])) or
(!is_numeric($coordinates[1])) or
(!is_numeric($coordinates[2])) or
(!is_numeric($coordinates[3])) or
($coordinates[0] <= 0) or
($coordinates[1] <= 0) or
($coordinates[2] < 0) or
($coordinates[3] < 0) or
($coordinates[2] >= $image->width()) or
($coordinates[3] >= $image->height())) {
return;
}
return [
(int) $coordinates[0],
(int) $coordinates[1],
(int) $coordinates[2],
(int) $coordinates[3],
];
} | php | public function getCoordinates(Image $image)
{
$coordinates = explode(',', $this->crop);
if (count($coordinates) !== 4 or
(!is_numeric($coordinates[0])) or
(!is_numeric($coordinates[1])) or
(!is_numeric($coordinates[2])) or
(!is_numeric($coordinates[3])) or
($coordinates[0] <= 0) or
($coordinates[1] <= 0) or
($coordinates[2] < 0) or
($coordinates[3] < 0) or
($coordinates[2] >= $image->width()) or
($coordinates[3] >= $image->height())) {
return;
}
return [
(int) $coordinates[0],
(int) $coordinates[1],
(int) $coordinates[2],
(int) $coordinates[3],
];
} | [
"public",
"function",
"getCoordinates",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"coordinates",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"crop",
")",
";",
"if",
"(",
"count",
"(",
"$",
"coordinates",
")",
"!==",
"4",
"or",
"(",
"!",
"is_numeric",
"(",
"$",
"coordinates",
"[",
"0",
"]",
")",
")",
"or",
"(",
"!",
"is_numeric",
"(",
"$",
"coordinates",
"[",
"1",
"]",
")",
")",
"or",
"(",
"!",
"is_numeric",
"(",
"$",
"coordinates",
"[",
"2",
"]",
")",
")",
"or",
"(",
"!",
"is_numeric",
"(",
"$",
"coordinates",
"[",
"3",
"]",
")",
")",
"or",
"(",
"$",
"coordinates",
"[",
"0",
"]",
"<=",
"0",
")",
"or",
"(",
"$",
"coordinates",
"[",
"1",
"]",
"<=",
"0",
")",
"or",
"(",
"$",
"coordinates",
"[",
"2",
"]",
"<",
"0",
")",
"or",
"(",
"$",
"coordinates",
"[",
"3",
"]",
"<",
"0",
")",
"or",
"(",
"$",
"coordinates",
"[",
"2",
"]",
">=",
"$",
"image",
"->",
"width",
"(",
")",
")",
"or",
"(",
"$",
"coordinates",
"[",
"3",
"]",
">=",
"$",
"image",
"->",
"height",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"return",
"[",
"(",
"int",
")",
"$",
"coordinates",
"[",
"0",
"]",
",",
"(",
"int",
")",
"$",
"coordinates",
"[",
"1",
"]",
",",
"(",
"int",
")",
"$",
"coordinates",
"[",
"2",
"]",
",",
"(",
"int",
")",
"$",
"coordinates",
"[",
"3",
"]",
",",
"]",
";",
"}"
] | Resolve coordinates.
@param Image $image The source image.
@return int[] The resolved coordinates. | [
"Resolve",
"coordinates",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Crop.php#L40-L64 | train |
thephpleague/glide | src/Manipulators/Crop.php | Crop.limitToImageBoundaries | public function limitToImageBoundaries(Image $image, array $coordinates)
{
if ($coordinates[0] > ($image->width() - $coordinates[2])) {
$coordinates[0] = $image->width() - $coordinates[2];
}
if ($coordinates[1] > ($image->height() - $coordinates[3])) {
$coordinates[1] = $image->height() - $coordinates[3];
}
return $coordinates;
} | php | public function limitToImageBoundaries(Image $image, array $coordinates)
{
if ($coordinates[0] > ($image->width() - $coordinates[2])) {
$coordinates[0] = $image->width() - $coordinates[2];
}
if ($coordinates[1] > ($image->height() - $coordinates[3])) {
$coordinates[1] = $image->height() - $coordinates[3];
}
return $coordinates;
} | [
"public",
"function",
"limitToImageBoundaries",
"(",
"Image",
"$",
"image",
",",
"array",
"$",
"coordinates",
")",
"{",
"if",
"(",
"$",
"coordinates",
"[",
"0",
"]",
">",
"(",
"$",
"image",
"->",
"width",
"(",
")",
"-",
"$",
"coordinates",
"[",
"2",
"]",
")",
")",
"{",
"$",
"coordinates",
"[",
"0",
"]",
"=",
"$",
"image",
"->",
"width",
"(",
")",
"-",
"$",
"coordinates",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"$",
"coordinates",
"[",
"1",
"]",
">",
"(",
"$",
"image",
"->",
"height",
"(",
")",
"-",
"$",
"coordinates",
"[",
"3",
"]",
")",
")",
"{",
"$",
"coordinates",
"[",
"1",
"]",
"=",
"$",
"image",
"->",
"height",
"(",
")",
"-",
"$",
"coordinates",
"[",
"3",
"]",
";",
"}",
"return",
"$",
"coordinates",
";",
"}"
] | Limit coordinates to image boundaries.
@param Image $image The source image.
@param int[] $coordinates The coordinates.
@return int[] The limited coordinates. | [
"Limit",
"coordinates",
"to",
"image",
"boundaries",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Crop.php#L72-L83 | train |
thephpleague/glide | src/Signatures/Signature.php | Signature.generateSignature | public function generateSignature($path, array $params)
{
unset($params['s']);
ksort($params);
return md5($this->signKey.':'.ltrim($path, '/').'?'.http_build_query($params));
} | php | public function generateSignature($path, array $params)
{
unset($params['s']);
ksort($params);
return md5($this->signKey.':'.ltrim($path, '/').'?'.http_build_query($params));
} | [
"public",
"function",
"generateSignature",
"(",
"$",
"path",
",",
"array",
"$",
"params",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"'s'",
"]",
")",
";",
"ksort",
"(",
"$",
"params",
")",
";",
"return",
"md5",
"(",
"$",
"this",
"->",
"signKey",
".",
"':'",
".",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"params",
")",
")",
";",
"}"
] | Generate an HTTP signature.
@param string $path The resource path.
@param array $params The manipulation parameters.
@return string The generated HTTP signature. | [
"Generate",
"an",
"HTTP",
"signature",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Signatures/Signature.php#L56-L62 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.run | public function run(Image $image)
{
$width = $this->getWidth();
$height = $this->getHeight();
$fit = $this->getFit();
$dpr = $this->getDpr();
list($width, $height) = $this->resolveMissingDimensions($image, $width, $height);
list($width, $height) = $this->applyDpr($width, $height, $dpr);
list($width, $height) = $this->limitImageSize($width, $height);
if ((int) $width !== (int) $image->width() or (int) $height !== (int) $image->height()) {
$image = $this->runResize($image, $fit, (int) $width, (int) $height);
}
return $image;
} | php | public function run(Image $image)
{
$width = $this->getWidth();
$height = $this->getHeight();
$fit = $this->getFit();
$dpr = $this->getDpr();
list($width, $height) = $this->resolveMissingDimensions($image, $width, $height);
list($width, $height) = $this->applyDpr($width, $height, $dpr);
list($width, $height) = $this->limitImageSize($width, $height);
if ((int) $width !== (int) $image->width() or (int) $height !== (int) $image->height()) {
$image = $this->runResize($image, $fit, (int) $width, (int) $height);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"width",
"=",
"$",
"this",
"->",
"getWidth",
"(",
")",
";",
"$",
"height",
"=",
"$",
"this",
"->",
"getHeight",
"(",
")",
";",
"$",
"fit",
"=",
"$",
"this",
"->",
"getFit",
"(",
")",
";",
"$",
"dpr",
"=",
"$",
"this",
"->",
"getDpr",
"(",
")",
";",
"list",
"(",
"$",
"width",
",",
"$",
"height",
")",
"=",
"$",
"this",
"->",
"resolveMissingDimensions",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"list",
"(",
"$",
"width",
",",
"$",
"height",
")",
"=",
"$",
"this",
"->",
"applyDpr",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"dpr",
")",
";",
"list",
"(",
"$",
"width",
",",
"$",
"height",
")",
"=",
"$",
"this",
"->",
"limitImageSize",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"if",
"(",
"(",
"int",
")",
"$",
"width",
"!==",
"(",
"int",
")",
"$",
"image",
"->",
"width",
"(",
")",
"or",
"(",
"int",
")",
"$",
"height",
"!==",
"(",
"int",
")",
"$",
"image",
"->",
"height",
"(",
")",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"runResize",
"(",
"$",
"image",
",",
"$",
"fit",
",",
"(",
"int",
")",
"$",
"width",
",",
"(",
"int",
")",
"$",
"height",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform size image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"size",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L53-L69 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.getFit | public function getFit()
{
if (in_array($this->fit, ['contain', 'fill', 'max', 'stretch'], true)) {
return $this->fit;
}
if (preg_match('/^(crop)(-top-left|-top|-top-right|-left|-center|-right|-bottom-left|-bottom|-bottom-right|-[\d]{1,3}-[\d]{1,3}(?:-[\d]{1,3}(?:\.\d+)?)?)*$/', $this->fit)) {
return 'crop';
}
return 'contain';
} | php | public function getFit()
{
if (in_array($this->fit, ['contain', 'fill', 'max', 'stretch'], true)) {
return $this->fit;
}
if (preg_match('/^(crop)(-top-left|-top|-top-right|-left|-center|-right|-bottom-left|-bottom|-bottom-right|-[\d]{1,3}-[\d]{1,3}(?:-[\d]{1,3}(?:\.\d+)?)?)*$/', $this->fit)) {
return 'crop';
}
return 'contain';
} | [
"public",
"function",
"getFit",
"(",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"fit",
",",
"[",
"'contain'",
",",
"'fill'",
",",
"'max'",
",",
"'stretch'",
"]",
",",
"true",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fit",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^(crop)(-top-left|-top|-top-right|-left|-center|-right|-bottom-left|-bottom|-bottom-right|-[\\d]{1,3}-[\\d]{1,3}(?:-[\\d]{1,3}(?:\\.\\d+)?)?)*$/'",
",",
"$",
"this",
"->",
"fit",
")",
")",
"{",
"return",
"'crop'",
";",
"}",
"return",
"'contain'",
";",
"}"
] | Resolve fit.
@return string The resolved fit. | [
"Resolve",
"fit",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L109-L120 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.getDpr | public function getDpr()
{
if (!is_numeric($this->dpr)) {
return 1.0;
}
if ($this->dpr < 0 or $this->dpr > 8) {
return 1.0;
}
return (double) $this->dpr;
} | php | public function getDpr()
{
if (!is_numeric($this->dpr)) {
return 1.0;
}
if ($this->dpr < 0 or $this->dpr > 8) {
return 1.0;
}
return (double) $this->dpr;
} | [
"public",
"function",
"getDpr",
"(",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"dpr",
")",
")",
"{",
"return",
"1.0",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dpr",
"<",
"0",
"or",
"$",
"this",
"->",
"dpr",
">",
"8",
")",
"{",
"return",
"1.0",
";",
"}",
"return",
"(",
"double",
")",
"$",
"this",
"->",
"dpr",
";",
"}"
] | Resolve the device pixel ratio.
@return double The device pixel ratio. | [
"Resolve",
"the",
"device",
"pixel",
"ratio",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L126-L137 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.resolveMissingDimensions | public function resolveMissingDimensions(Image $image, $width, $height)
{
if (is_null($width) and is_null($height)) {
$width = $image->width();
$height = $image->height();
}
if (is_null($width)) {
$width = $height * ($image->width() / $image->height());
}
if (is_null($height)) {
$height = $width / ($image->width() / $image->height());
}
return [
(int) $width,
(int) $height,
];
} | php | public function resolveMissingDimensions(Image $image, $width, $height)
{
if (is_null($width) and is_null($height)) {
$width = $image->width();
$height = $image->height();
}
if (is_null($width)) {
$width = $height * ($image->width() / $image->height());
}
if (is_null($height)) {
$height = $width / ($image->width() / $image->height());
}
return [
(int) $width,
(int) $height,
];
} | [
"public",
"function",
"resolveMissingDimensions",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"width",
")",
"and",
"is_null",
"(",
"$",
"height",
")",
")",
"{",
"$",
"width",
"=",
"$",
"image",
"->",
"width",
"(",
")",
";",
"$",
"height",
"=",
"$",
"image",
"->",
"height",
"(",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"width",
")",
")",
"{",
"$",
"width",
"=",
"$",
"height",
"*",
"(",
"$",
"image",
"->",
"width",
"(",
")",
"/",
"$",
"image",
"->",
"height",
"(",
")",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"height",
")",
")",
"{",
"$",
"height",
"=",
"$",
"width",
"/",
"(",
"$",
"image",
"->",
"width",
"(",
")",
"/",
"$",
"image",
"->",
"height",
"(",
")",
")",
";",
"}",
"return",
"[",
"(",
"int",
")",
"$",
"width",
",",
"(",
"int",
")",
"$",
"height",
",",
"]",
";",
"}"
] | Resolve missing image dimensions.
@param Image $image The source image.
@param integer|null $width The image width.
@param integer|null $height The image height.
@return integer[] The resolved width and height. | [
"Resolve",
"missing",
"image",
"dimensions",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L146-L165 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.applyDpr | public function applyDpr($width, $height, $dpr)
{
$width = $width * $dpr;
$height = $height * $dpr;
return [
(int) $width,
(int) $height,
];
} | php | public function applyDpr($width, $height, $dpr)
{
$width = $width * $dpr;
$height = $height * $dpr;
return [
(int) $width,
(int) $height,
];
} | [
"public",
"function",
"applyDpr",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"dpr",
")",
"{",
"$",
"width",
"=",
"$",
"width",
"*",
"$",
"dpr",
";",
"$",
"height",
"=",
"$",
"height",
"*",
"$",
"dpr",
";",
"return",
"[",
"(",
"int",
")",
"$",
"width",
",",
"(",
"int",
")",
"$",
"height",
",",
"]",
";",
"}"
] | Apply the device pixel ratio.
@param integer $width The target image width.
@param integer $height The target image height.
@param integer $dpr The device pixel ratio.
@return integer[] The modified width and height. | [
"Apply",
"the",
"device",
"pixel",
"ratio",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L174-L183 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.