Fix bin/publish: copy docs.dist from project root

Fix bin/publish: use correct .env path for rspade_system
Fix bin/publish script: prevent grep exit code 1 from terminating script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-21 02:08:33 +00:00
commit f6fac6c4bc
79758 changed files with 10547827 additions and 0 deletions

View File

@@ -0,0 +1,182 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock;
/**
* The context in which a DocBlock occurs.
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class Context
{
/** @var string The current namespace. */
protected $namespace = '';
/** @var array List of namespace aliases => Fully Qualified Namespace. */
protected $namespace_aliases = array();
/** @var string Name of the structural element, within the namespace. */
protected $lsen = '';
/** @var string[] List of generics */
protected $generics = array();
/**
* Cteates a new context.
* @param string $namespace The namespace where this DocBlock
* resides in.
* @param array $namespace_aliases List of namespace aliases => Fully
* Qualified Namespace.
* @param string $lsen Name of the structural element, within
* the namespace.
*/
public function __construct(
$namespace = '',
array $namespace_aliases = array(),
$lsen = '',
array $generics = array()
) {
if (!empty($namespace)) {
$this->setNamespace($namespace);
}
$this->setNamespaceAliases($namespace_aliases);
$this->setLSEN($lsen);
$this->setGenerics($generics);
}
/**
* @return string The namespace where this DocBlock resides in.
*/
public function getNamespace()
{
return $this->namespace;
}
/**
* @return array List of namespace aliases => Fully Qualified Namespace.
*/
public function getNamespaceAliases()
{
return $this->namespace_aliases;
}
/**
* Returns the Local Structural Element Name.
*
* @return string Name of the structural element, within the namespace.
*/
public function getLSEN()
{
return $this->lsen;
}
/**
* Returns the list of generics.
*
* @return string[] List of generics
*/
public function getGenerics()
{
return $this->generics;
}
/**
* Sets a new namespace.
*
* Sets a new namespace for the context. Leading and trailing slashes are
* trimmed, and the keywords "global" and "default" are treated as aliases
* to no namespace.
*
* @param string $namespace The new namespace to set.
*
* @return $this
*/
public function setNamespace($namespace)
{
if ('global' !== $namespace
&& 'default' !== $namespace
) {
// Srip leading and trailing slash
$this->namespace = trim((string)$namespace, '\\');
} else {
$this->namespace = '';
}
return $this;
}
/**
* Sets the namespace aliases, replacing all previous ones.
*
* @param array $namespace_aliases List of namespace aliases => Fully
* Qualified Namespace.
*
* @return $this
*/
public function setNamespaceAliases(array $namespace_aliases)
{
$this->namespace_aliases = array();
foreach ($namespace_aliases as $alias => $fqnn) {
$this->setNamespaceAlias($alias, $fqnn);
}
return $this;
}
/**
* Adds a namespace alias to the context.
*
* @param string $alias The alias name (the part after "as", or the last
* part of the Fully Qualified Namespace Name) to add.
* @param string $fqnn The Fully Qualified Namespace Name for this alias.
* Any form of leading/trailing slashes are accepted, but what will be
* stored is a name, prefixed with a slash, and no trailing slash.
*
* @return $this
*/
public function setNamespaceAlias($alias, $fqnn)
{
$this->namespace_aliases[$alias] = '\\' . trim((string)$fqnn, '\\');
return $this;
}
/**
* Sets a new Local Structural Element Name.
*
* Sets a new Local Structural Element Name. A local name also contains
* punctuation determining the kind of structural element (e.g. trailing "("
* and ")" for functions and methods).
*
* @param string $lsen The new local name of a structural element.
*
* @return $this
*/
public function setLSEN($lsen)
{
$this->lsen = (string)$lsen;
return $this;
}
/**
* Sets a new list of generics.
*
* @param string[] $generics The new list of generics.
*
* @return $this
*/
public function setGenerics(array $generics)
{
$this->generics = $generics;
return $this;
}
}

View File

@@ -0,0 +1,422 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock;
use ArrayIterator;
use InvalidArgumentException;
use ReflectionClass;
use ReflectionClassConstant;
use ReflectionMethod;
use ReflectionParameter;
use ReflectionProperty;
use Reflector;
use RuntimeException;
use UnexpectedValueException;
use function define;
use function defined;
use function file_exists;
use function file_get_contents;
use function get_class;
use function in_array;
use function is_string;
use function strrpos;
use function substr;
use function token_get_all;
use function trim;
use const T_AS;
use const T_CLASS;
use const T_CURLY_OPEN;
use const T_DOLLAR_OPEN_CURLY_BRACES;
use const T_NAME_FULLY_QUALIFIED;
use const T_NAME_QUALIFIED;
use const T_NAMESPACE;
use const T_NS_SEPARATOR;
use const T_STRING;
use const T_TRAIT;
use const T_USE;
if (!defined('T_NAME_QUALIFIED')) {
define('T_NAME_QUALIFIED', 10001);
}
if (!defined('T_NAME_FULLY_QUALIFIED')) {
define('T_NAME_FULLY_QUALIFIED', 10002);
}
/**
* Convenience class to create a Context for DocBlocks when not using the Reflection Component of phpDocumentor.
*
* For a DocBlock to be able to resolve types that use partial namespace names or rely on namespace imports we need to
* provide a bit of context so that the DocBlock can read that and based on it decide how to resolve the types to
* Fully Qualified names.
*
* @see Context for more information.
*/
final class ContextFactory
{
/** The literal used at the end of a use statement. */
private const T_LITERAL_END_OF_USE = ';';
/** The literal used between sets of use statements */
private const T_LITERAL_USE_SEPARATOR = ',';
/**
* Build a Context given a Class Reflection.
*
* @see Context for more information on Contexts.
*/
public function createFromReflector(Reflector $reflector): Context
{
if ($reflector instanceof ReflectionClass) {
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
/** @var ReflectionClass<object> $reflector */
return $this->createFromReflectionClass($reflector);
}
if ($reflector instanceof ReflectionParameter) {
return $this->createFromReflectionParameter($reflector);
}
if ($reflector instanceof ReflectionMethod) {
return $this->createFromReflectionMethod($reflector);
}
if ($reflector instanceof ReflectionProperty) {
return $this->createFromReflectionProperty($reflector);
}
if ($reflector instanceof ReflectionClassConstant) {
return $this->createFromReflectionClassConstant($reflector);
}
throw new UnexpectedValueException('Unhandled \Reflector instance given: ' . get_class($reflector));
}
private function createFromReflectionParameter(ReflectionParameter $parameter): Context
{
$class = $parameter->getDeclaringClass();
if (!$class) {
throw new InvalidArgumentException('Unable to get class of ' . $parameter->getName());
}
return $this->createFromReflectionClass($class);
}
private function createFromReflectionMethod(ReflectionMethod $method): Context
{
$class = $method->getDeclaringClass();
return $this->createFromReflectionClass($class);
}
private function createFromReflectionProperty(ReflectionProperty $property): Context
{
$class = $property->getDeclaringClass();
return $this->createFromReflectionClass($class);
}
private function createFromReflectionClassConstant(ReflectionClassConstant $constant): Context
{
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
/** @phpstan-var ReflectionClass<object> $class */
$class = $constant->getDeclaringClass();
return $this->createFromReflectionClass($class);
}
/**
* @phpstan-param ReflectionClass<object> $class
*/
private function createFromReflectionClass(ReflectionClass $class): Context
{
$fileName = $class->getFileName();
$namespace = $class->getNamespaceName();
if (is_string($fileName) && file_exists($fileName)) {
$contents = file_get_contents($fileName);
if ($contents === false) {
throw new RuntimeException('Unable to read file "' . $fileName . '"');
}
return $this->createForNamespace($namespace, $contents);
}
return new Context($namespace, []);
}
/**
* Build a Context for a namespace in the provided file contents.
*
* @see Context for more information on Contexts.
*
* @param string $namespace It does not matter if a `\` precedes the namespace name,
* this method first normalizes.
* @param string $fileContents The file's contents to retrieve the aliases from with the given namespace.
*/
public function createForNamespace(string $namespace, string $fileContents): Context
{
$namespace = trim($namespace, '\\');
$useStatements = [];
$currentNamespace = '';
$tokens = new ArrayIterator(token_get_all($fileContents));
while ($tokens->valid()) {
$currentToken = $tokens->current();
switch ($currentToken[0]) {
case T_NAMESPACE:
$currentNamespace = $this->parseNamespace($tokens);
break;
case T_CLASS:
case T_TRAIT:
// Fast-forward the iterator through the class so that any
// T_USE tokens found within are skipped - these are not
// valid namespace use statements so should be ignored.
$braceLevel = 0;
$firstBraceFound = false;
while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) {
$currentToken = $tokens->current();
if (
$currentToken === '{'
|| in_array($currentToken[0], [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], true)
) {
if (!$firstBraceFound) {
$firstBraceFound = true;
}
++$braceLevel;
}
if ($currentToken === '}') {
--$braceLevel;
}
$tokens->next();
}
break;
case T_USE:
if ($currentNamespace === $namespace) {
$useStatements += $this->parseUseStatement($tokens);
}
break;
}
$tokens->next();
}
return new Context($namespace, $useStatements);
}
/**
* Deduce the name from tokens when we are at the T_NAMESPACE token.
*
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
*/
private function parseNamespace(ArrayIterator $tokens): string
{
// skip to the first string or namespace separator
$this->skipToNextStringOrNamespaceSeparator($tokens);
$name = '';
$acceptedTokens = [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED];
while ($tokens->valid() && in_array($tokens->current()[0], $acceptedTokens, true)) {
$name .= $tokens->current()[1];
$tokens->next();
}
return $name;
}
/**
* Deduce the names of all imports when we are at the T_USE token.
*
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
*
* @return string[]
* @psalm-return array<string, string>
*/
private function parseUseStatement(ArrayIterator $tokens): array
{
$uses = [];
while ($tokens->valid()) {
$this->skipToNextStringOrNamespaceSeparator($tokens);
$uses += $this->extractUseStatements($tokens);
$currentToken = $tokens->current();
if ($currentToken[0] === self::T_LITERAL_END_OF_USE) {
return $uses;
}
}
return $uses;
}
/**
* Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token.
*
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
*/
private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens): void
{
while ($tokens->valid()) {
$currentToken = $tokens->current();
if (in_array($currentToken[0], [T_STRING, T_NS_SEPARATOR], true)) {
break;
}
if ($currentToken[0] === T_NAME_QUALIFIED) {
break;
}
if (defined('T_NAME_FULLY_QUALIFIED') && $currentToken[0] === T_NAME_FULLY_QUALIFIED) {
break;
}
$tokens->next();
}
}
/**
* Deduce the namespace name and alias of an import when we are at the T_USE token or have not reached the end of
* a USE statement yet. This will return a key/value array of the alias => namespace.
*
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
*
* @return string[]
* @psalm-return array<string, string>
*
* @psalm-suppress TypeDoesNotContainType
*/
private function extractUseStatements(ArrayIterator $tokens): array
{
$extractedUseStatements = [];
$groupedNs = '';
$currentNs = '';
$currentAlias = '';
$state = 'start';
while ($tokens->valid()) {
$currentToken = $tokens->current();
$tokenId = is_string($currentToken) ? $currentToken : $currentToken[0];
$tokenValue = is_string($currentToken) ? null : $currentToken[1];
switch ($state) {
case 'start':
switch ($tokenId) {
case T_STRING:
case T_NS_SEPARATOR:
$currentNs .= (string) $tokenValue;
$currentAlias = $tokenValue;
break;
case T_NAME_QUALIFIED:
case T_NAME_FULLY_QUALIFIED:
$currentNs .= (string) $tokenValue;
$currentAlias = substr(
(string) $tokenValue,
(int) (strrpos((string) $tokenValue, '\\')) + 1
);
break;
case T_CURLY_OPEN:
case '{':
$state = 'grouped';
$groupedNs = $currentNs;
break;
case T_AS:
$state = 'start-alias';
break;
case self::T_LITERAL_USE_SEPARATOR:
case self::T_LITERAL_END_OF_USE:
$state = 'end';
break;
default:
break;
}
break;
case 'start-alias':
switch ($tokenId) {
case T_STRING:
$currentAlias = $tokenValue;
break;
case self::T_LITERAL_USE_SEPARATOR:
case self::T_LITERAL_END_OF_USE:
$state = 'end';
break;
default:
break;
}
break;
case 'grouped':
switch ($tokenId) {
case T_STRING:
case T_NS_SEPARATOR:
$currentNs .= (string) $tokenValue;
$currentAlias = $tokenValue;
break;
case T_AS:
$state = 'grouped-alias';
break;
case self::T_LITERAL_USE_SEPARATOR:
$state = 'grouped';
$extractedUseStatements[(string) $currentAlias] = $currentNs;
$currentNs = $groupedNs;
$currentAlias = '';
break;
case self::T_LITERAL_END_OF_USE:
$state = 'end';
break;
default:
break;
}
break;
case 'grouped-alias':
switch ($tokenId) {
case T_STRING:
$currentAlias = $tokenValue;
break;
case self::T_LITERAL_USE_SEPARATOR:
$state = 'grouped';
$extractedUseStatements[(string) $currentAlias] = $currentNs;
$currentNs = $groupedNs;
$currentAlias = '';
break;
case self::T_LITERAL_END_OF_USE:
$state = 'end';
break;
default:
break;
}
}
if ($state === 'end') {
break;
}
$tokens->next();
}
if ($groupedNs !== $currentNs) {
$extractedUseStatements[(string) $currentAlias] = $currentNs;
}
return $extractedUseStatements;
}
}

View File

@@ -0,0 +1,223 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock;
/**
* Parses a Description of a DocBlock or tag.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class Description implements \Reflector
{
/** @var string */
protected $contents = '';
/** @var array The contents, as an array of strings and Tag objects. */
protected $parsedContents = null;
/** @var DocBlock The DocBlock which this description belongs to. */
protected $docblock = null;
/**
* Populates the fields of a description.
*
* @param string $content The description's contents.
* @param DocBlock $docblock The DocBlock which this description belongs to.
*/
public function __construct($content, ?DocBlock $docblock = null)
{
$this->setContent($content)->setDocBlock($docblock);
}
/**
* Gets the text of this description.
*
* @return string
*/
public function getContents()
{
return $this->contents;
}
/**
* Sets the text of this description.
*
* @param string $content The new text of this description.
*
* @return $this
*/
public function setContent($content)
{
$this->contents = trim($content);
$this->parsedContents = null;
return $this;
}
/**
* Returns the parsed text of this description.
*
* @return array An array of strings and tag objects, in the order they
* occur within the description.
*/
public function getParsedContents()
{
if (null === $this->parsedContents) {
$this->parsedContents = preg_split(
'/\{
# "{@}" is not a valid inline tag. This ensures that
# we do not treat it as one, but treat it literally.
(?!@\})
# We want to capture the whole tag line, but without the
# inline tag delimiters.
(\@
# Match everything up to the next delimiter.
[^{}]*
# Nested inline tag content should not be captured, or
# it will appear in the result separately.
(?:
# Match nested inline tags.
(?:
# Because we did not catch the tag delimiters
# earlier, we must be explicit with them here.
# Notice that this also matches "{}", as a way
# to later introduce it as an escape sequence.
\{(?1)?\}
|
# Make sure we match hanging "{".
\{
)
# Match content after the nested inline tag.
[^{}]*
)* # If there are more inline tags, match them as well.
# We use "*" since there may not be any nested inline
# tags.
)
\}/Sux',
$this->contents,
-1,
PREG_SPLIT_DELIM_CAPTURE
);
$count = count($this->parsedContents);
for ($i=1; $i<$count; $i += 2) {
$this->parsedContents[$i] = Tag::createInstance(
$this->parsedContents[$i],
$this->docblock
);
}
//In order to allow "literal" inline tags, the otherwise invalid
//sequence "{@}" is changed to "@", and "{}" is changed to "}".
//See unit tests for examples.
for ($i=0; $i<$count; $i += 2) {
$this->parsedContents[$i] = str_replace(
array('{@}', '{}'),
array('@', '}'),
$this->parsedContents[$i]
);
}
}
return $this->parsedContents;
}
/**
* Return a formatted variant of the Long Description using MarkDown.
*
* @todo this should become a more intelligent piece of code where the
* configuration contains a setting what format long descriptions are.
*
* @codeCoverageIgnore Will be removed soon, in favor of adapters at
* PhpDocumentor itself that will process text in various formats.
*
* @return string
*/
public function getFormattedContents()
{
$result = $this->contents;
// if the long description contains a plain HTML <code> element, surround
// it with a pre element. Please note that we explicitly used str_replace
// and not preg_replace to gain performance
if (strpos($result, '<code>') !== false) {
$result = str_replace(
array('<code>', "<code>\r\n", "<code>\n", "<code>\r", '</code>'),
array('<pre><code>', '<code>', '<code>', '<code>', '</code></pre>'),
$result
);
}
if (class_exists('Parsedown')) {
$markdown = \Parsedown::instance();
$result = $markdown->parse($result);
} elseif (class_exists('dflydev\markdown\MarkdownExtraParser')) {
$markdown = new \dflydev\markdown\MarkdownExtraParser();
$result = $markdown->transformMarkdown($result);
}
return trim($result);
}
/**
* Gets the docblock this tag belongs to.
*
* @return DocBlock The docblock this description belongs to.
*/
public function getDocBlock()
{
return $this->docblock;
}
/**
* Sets the docblock this tag belongs to.
*
* @param DocBlock $docblock The new docblock this description belongs to.
* Setting NULL removes any association.
*
* @return $this
*/
public function setDocBlock(?DocBlock $docblock = null)
{
$this->docblock = $docblock;
return $this;
}
/**
* Builds a string representation of this object.
*
* @todo determine the exact format as used by PHP Reflection
* and implement it.
*
* @return void
* @codeCoverageIgnore Not yet implemented
*/
public static function export()
{
throw new \Exception('Not yet implemented');
}
/**
* Returns the long description as a string.
*
* @return string
*/
public function __toString()
{
return $this->getContents();
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock;
/**
* The location a DocBlock occurs within a file.
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class Location
{
/** @var int Line where the DocBlock text starts. */
protected $lineNumber = 0;
/** @var int Column where the DocBlock text starts. */
protected $columnNumber = 0;
public function __construct(
$lineNumber = 0,
$columnNumber = 0
) {
$this->setLineNumber($lineNumber)->setColumnNumber($columnNumber);
}
/**
* @return int Line where the DocBlock text starts.
*/
public function getLineNumber()
{
return $this->lineNumber;
}
/**
*
* @param type $lineNumber
* @return $this
*/
public function setLineNumber($lineNumber)
{
$this->lineNumber = (int)$lineNumber;
return $this;
}
/**
* @return int Column where the DocBlock text starts.
*/
public function getColumnNumber()
{
return $this->columnNumber;
}
/**
*
* @param int $columnNumber
* @return $this
*/
public function setColumnNumber($columnNumber)
{
$this->columnNumber = (int)$columnNumber;
return $this;
}
}

View File

@@ -0,0 +1,235 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Barry vd. Heuvel <barryvdh@gmail.com>
* @copyright 2013 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock;
/**
* Serializes a DocBlock instance.
*
* @author Barry vd. Heuvel <barryvdh@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class Serializer
{
/** @var string The string to indent the comment with. */
protected $indentString = ' ';
/** @var int The number of times the indent string is repeated. */
protected $indent = 0;
/** @var bool Whether to indent the first line. */
protected $isFirstLineIndented = true;
/** @var int|null The max length of a line. */
protected $lineLength = null;
/** @var bool Separate tag groups. */
protected $separateTags = false;
/**
* Create a Serializer instance.
*
* @param int $indent The number of times the indent string is
* repeated.
* @param string $indentString The string to indent the comment with.
* @param bool $indentFirstLine Whether to indent the first line.
* @param int|null $lineLength The max length of a line or NULL to
* disable line wrapping.
* @param bool $separateTags Separate tag groups.
*/
public function __construct(
$indent = 0,
$indentString = ' ',
$indentFirstLine = true,
$lineLength = null,
$separateTags = false
) {
$this->setIndentationString($indentString);
$this->setIndent($indent);
$this->setIsFirstLineIndented($indentFirstLine);
$this->setLineLength($lineLength);
$this->setSeparateTags($separateTags);
}
/**
* Sets the string to indent comments with.
*
* @param string $indentationString The string to indent comments with.
*
* @return $this This serializer object.
*/
public function setIndentationString($indentString)
{
$this->indentString = (string)$indentString;
return $this;
}
/**
* Gets the string to indent comments with.
*
* @return string The indent string.
*/
public function getIndentationString()
{
return $this->indentString;
}
/**
* Sets the number of indents.
*
* @param int $indent The number of times the indent string is repeated.
*
* @return $this This serializer object.
*/
public function setIndent($indent)
{
$this->indent = (int)$indent;
return $this;
}
/**
* Gets the number of indents.
*
* @return int The number of times the indent string is repeated.
*/
public function getIndent()
{
return $this->indent;
}
/**
* Sets whether or not the first line should be indented.
*
* Sets whether or not the first line (the one with the "/**") should be
* indented.
*
* @param bool $indentFirstLine The new value for this setting.
*
* @return $this This serializer object.
*/
public function setIsFirstLineIndented($indentFirstLine)
{
$this->isFirstLineIndented = (bool)$indentFirstLine;
return $this;
}
/**
* Gets whether or not the first line should be indented.
*
* @return bool Whether or not the first line should be indented.
*/
public function isFirstLineIndented()
{
return $this->isFirstLineIndented;
}
/**
* Sets the line length.
*
* Sets the length of each line in the serialization. Content will be
* wrapped within this limit.
*
* @param int|null $lineLength The length of each line. NULL to disable line
* wrapping altogether.
*
* @return $this This serializer object.
*/
public function setLineLength($lineLength)
{
$this->lineLength = null === $lineLength ? null : (int)$lineLength;
return $this;
}
/**
* Gets the line length.
*
* @return int|null The length of each line or NULL if line wrapping is
* disabled.
*/
public function getLineLength()
{
return $this->lineLength;
}
/**
* Sets whether there should be an empty line between tag groups.
*
* @param bool $separateTags The new value for this setting.
*
* @return $this This serializer object.
*/
public function setSeparateTags($separateTags)
{
$this->separateTags = (bool)$separateTags;
return $this;
}
/**
* Gets whether there should be an empty line between tag groups.
*
* @return bool Whether there should be an empty line between tag groups.
*/
public function getSeparateTags()
{
return $this->separateTags;
}
/**
* Generate a DocBlock comment.
*
* @param DocBlock The DocBlock to serialize.
*
* @return string The serialized doc block.
*/
public function getDocComment(DocBlock $docblock)
{
$indent = str_repeat($this->indentString, $this->indent);
$firstIndent = $this->isFirstLineIndented ? $indent : '';
$text = $docblock->getText();
if ($this->lineLength) {
//3 === strlen(' * ')
$wrapLength = $this->lineLength - strlen($indent) - 3;
$text = wordwrap($text, $wrapLength);
}
$text = str_replace("\n", "\n{$indent} * ", $text);
$comment = !empty($text)? "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n" : "{$firstIndent}/**\n";
$tags = array_values($docblock->getTags());
/** @var Tag $tag */
foreach ($tags as $key => $tag) {
$nextTag = isset($tags[$key + 1]) ? $tags[$key + 1] : null;
$tagText = (string) $tag;
if ($this->lineLength) {
$tagText = wordwrap($tagText, $wrapLength);
}
$tagText = str_replace("\n", "\n{$indent} * ", $tagText);
$comment .= "{$indent} * {$tagText}\n";
if ($this->separateTags && $nextTag !== null && ! $tag->inSameGroup($nextTag)) {
$comment .= "{$indent} *\n";
}
}
$comment .= $indent . ' */';
return $comment;
}
}

View File

@@ -0,0 +1,414 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock;
/**
* Parses a tag definition for a DocBlock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class Tag implements \Reflector
{
/**
* PCRE regular expression matching a tag name.
*/
const REGEX_TAGNAME = '[\w\-\_\\\\]+';
/** @var string Name of the tag */
protected $tag = '';
/**
* @var string|null Content of the tag.
* When set to NULL, it means it needs to be regenerated.
*/
protected $content = '';
/** @var string Description of the content of this tag */
protected $description = '';
/**
* @var array|null The description, as an array of strings and Tag objects.
* When set to NULL, it means it needs to be regenerated.
*/
protected $parsedDescription = null;
/** @var Location Location of the tag. */
protected $location = null;
/** @var DocBlock The DocBlock which this tag belongs to. */
protected $docblock = null;
/**
* @var array An array with a tag as a key, and an FQCN to a class that
* handles it as an array value. The class is expected to inherit this
* class.
*/
private static $tagHandlerMappings = array(
'author'
=> '\Barryvdh\Reflection\DocBlock\Tag\AuthorTag',
'covers'
=> '\Barryvdh\Reflection\DocBlock\Tag\CoversTag',
'deprecated'
=> '\Barryvdh\Reflection\DocBlock\Tag\DeprecatedTag',
'example'
=> '\Barryvdh\Reflection\DocBlock\Tag\ExampleTag',
'link'
=> '\Barryvdh\Reflection\DocBlock\Tag\LinkTag',
'method'
=> '\Barryvdh\Reflection\DocBlock\Tag\MethodTag',
'param'
=> '\Barryvdh\Reflection\DocBlock\Tag\ParamTag',
'property-read'
=> '\Barryvdh\Reflection\DocBlock\Tag\PropertyReadTag',
'property'
=> '\Barryvdh\Reflection\DocBlock\Tag\PropertyTag',
'property-write'
=> '\Barryvdh\Reflection\DocBlock\Tag\PropertyWriteTag',
'return'
=> '\Barryvdh\Reflection\DocBlock\Tag\ReturnTag',
'see'
=> '\Barryvdh\Reflection\DocBlock\Tag\SeeTag',
'since'
=> '\Barryvdh\Reflection\DocBlock\Tag\SinceTag',
'source'
=> '\Barryvdh\Reflection\DocBlock\Tag\SourceTag',
'throw'
=> '\Barryvdh\Reflection\DocBlock\Tag\ThrowsTag',
'throws'
=> '\Barryvdh\Reflection\DocBlock\Tag\ThrowsTag',
'uses'
=> '\Barryvdh\Reflection\DocBlock\Tag\UsesTag',
'var'
=> '\Barryvdh\Reflection\DocBlock\Tag\VarTag',
'version'
=> '\Barryvdh\Reflection\DocBlock\Tag\VersionTag',
'SuppressWarnings'
=> '\Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag',
'template'
=> '\Barryvdh\Reflection\DocBlock\Tag\TemplateTag'
);
/**
* Factory method responsible for instantiating the correct sub type.
*
* @param string $tag_line The text for this tag, including description.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*
* @throws \InvalidArgumentException if an invalid tag line was presented.
*
* @return static A new tag object.
*/
final public static function createInstance(
$tag_line,
?DocBlock $docblock = null,
?Location $location = null
) {
if (!preg_match(
'/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)?/us',
$tag_line,
$matches
)) {
throw new \InvalidArgumentException(
'Invalid tag_line detected: ' . $tag_line
);
}
$handler = __CLASS__;
if (isset(self::$tagHandlerMappings[$matches[1]])) {
$handler = self::$tagHandlerMappings[$matches[1]];
} elseif (isset($docblock)) {
$tagName = (string)new Type\Collection(
array($matches[1]),
$docblock->getContext()
);
if (isset(self::$tagHandlerMappings[$tagName])) {
$handler = self::$tagHandlerMappings[$tagName];
}
}
return new $handler(
$matches[1],
isset($matches[2]) ? $matches[2] : '',
$docblock,
$location
);
}
/**
* Registers a handler for tags.
*
* Registers a handler for tags. The class specified is autoloaded if it's
* not available. It must inherit from this class.
*
* @param string $tag Name of tag to regiser a handler for. When
* registering a namespaced tag, the full name, along with a prefixing
* slash MUST be provided.
* @param string|null $handler FQCN of handler. Specifing NULL removes the
* handler for the specified tag, if any.
*
* @return bool TRUE on success, FALSE on failure.
*/
final public static function registerTagHandler($tag, $handler)
{
$tag = trim((string)$tag);
if (null === $handler) {
unset(self::$tagHandlerMappings[$tag]);
return true;
}
if ('' !== $tag
&& class_exists($handler, true)
&& is_subclass_of($handler, __CLASS__)
&& !strpos($tag, '\\') //Accept no slash, and 1st slash at offset 0.
) {
self::$tagHandlerMappings[$tag] = $handler;
return true;
}
return false;
}
/**
* Parses a tag and populates the member variables.
*
* @param string $name Name of the tag.
* @param string $content The contents of the given tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/
public function __construct(
$name,
$content,
?DocBlock $docblock = null,
?Location $location = null
) {
$this
->setName($name)
->setContent($content)
->setDocBlock($docblock)
->setLocation($location);
}
/**
* Gets the name of this tag.
*
* @return string The name of this tag.
*/
public function getName()
{
return $this->tag;
}
/**
* Sets the name of this tag.
*
* @param string $name The new name of this tag.
*
* @return $this
* @throws \InvalidArgumentException When an invalid tag name is provided.
*/
public function setName($name)
{
if (!preg_match('/^' . self::REGEX_TAGNAME . '$/u', $name)) {
throw new \InvalidArgumentException(
'Invalid tag name supplied: ' . $name
);
}
$this->tag = $name;
return $this;
}
/**
* Gets the content of this tag.
*
* @return string
*/
public function getContent()
{
if (null === $this->content) {
$this->content = $this->description;
}
return $this->content;
}
/**
* Sets the content of this tag.
*
* @param string $content The new content of this tag.
*
* @return $this
*/
public function setContent($content)
{
$this->setDescription($content);
$this->content = $content;
return $this;
}
/**
* Gets the description component of this tag.
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Sets the description component of this tag.
*
* @param string $description The new description component of this tag.
*
* @return $this
*/
public function setDescription($description)
{
$this->content = null;
$this->parsedDescription = null;
$this->description = trim($description);
return $this;
}
/**
* Gets the parsed text of this description.
*
* @return array An array of strings and tag objects, in the order they
* occur within the description.
*/
public function getParsedDescription()
{
if (null === $this->parsedDescription) {
$description = new Description($this->description, $this->docblock);
$this->parsedDescription = $description->getParsedContents();
}
return $this->parsedDescription;
}
/**
* Gets the docblock this tag belongs to.
*
* @return DocBlock The docblock this tag belongs to.
*/
public function getDocBlock()
{
return $this->docblock;
}
/**
* Sets the docblock this tag belongs to.
*
* @param DocBlock $docblock The new docblock this tag belongs to. Setting
* NULL removes any association.
*
* @return $this
*/
public function setDocBlock(?DocBlock $docblock = null)
{
$this->docblock = $docblock;
return $this;
}
/**
* Gets the location of the tag.
*
* @return Location The tag's location.
*/
public function getLocation()
{
return $this->location;
}
/**
* Sets the location of the tag.
*
* @param Location $location The new location of the tag.
*
* @return $this
*/
public function setLocation(?Location $location = null)
{
$this->location = $location;
return $this;
}
/**
* If the given tags should be together or apart.
*
* @param Tag $tag
*
* @return bool
*/
public function inSameGroup(Tag $tag)
{
$firstName = $this->getName();
$secondName = $tag->getName();
if ($firstName === $secondName) {
return true;
}
$groups = array(
array('deprecated', 'link', 'see', 'since'),
array('author', 'copyright', 'license'),
array('category', 'package', 'subpackage'),
array('property', 'property-read', 'property-write'),
array('param', 'return'),
);
foreach ($groups as $group) {
if (in_array($firstName, $group, true) && in_array($secondName, $group, true)) {
return true;
}
}
return false;
}
/**
* Builds a string representation of this object.
*
* @todo determine the exact format as used by PHP Reflection and implement it.
*
* @return void
* @codeCoverageIgnore Not yet implemented
*/
public static function export()
{
throw new \Exception('Not yet implemented');
}
/**
* Returns the tag as a serialized string
*
* @return string
*/
public function __toString()
{
return trim("@{$this->getName()} {$this->getContent()}");
}
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for an @author tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class AuthorTag extends Tag
{
/**
* PCRE regular expression matching any valid value for the name component.
*/
const REGEX_AUTHOR_NAME = '[^\<]*';
/**
* PCRE regular expression matching any valid value for the email component.
*/
const REGEX_AUTHOR_EMAIL = '[^\>]*';
/** @var string The name of the author */
protected $authorName = '';
/** @var string The email of the author */
protected $authorEmail = '';
public function getContent()
{
if (null === $this->content) {
$this->content = $this->authorName;
if ('' != $this->authorEmail) {
$this->content .= "<{$this->authorEmail}>";
}
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
if (preg_match(
'/^(' . self::REGEX_AUTHOR_NAME .
')(\<(' . self::REGEX_AUTHOR_EMAIL .
')\>)?$/u',
$this->description,
$matches
)) {
$this->authorName = trim($matches[1]);
if (isset($matches[3])) {
$this->authorEmail = trim($matches[3]);
}
}
return $this;
}
/**
* Gets the author's name.
*
* @return string The author's name.
*/
public function getAuthorName()
{
return $this->authorName;
}
/**
* Sets the author's name.
*
* @param string $authorName The new author name.
* An invalid value will set an empty string.
*
* @return $this
*/
public function setAuthorName($authorName)
{
$this->content = null;
$this->authorName
= preg_match('/^' . self::REGEX_AUTHOR_NAME . '$/u', $authorName)
? $authorName : '';
return $this;
}
/**
* Gets the author's email.
*
* @return string The author's email.
*/
public function getAuthorEmail()
{
return $this->authorEmail;
}
/**
* Sets the author's email.
*
* @param string $authorEmail The new author email.
* An invalid value will set an empty string.
*
* @return $this
*/
public function setAuthorEmail($authorEmail)
{
$this->authorEmail
= preg_match('/^' . self::REGEX_AUTHOR_EMAIL . '$/u', $authorEmail)
? $authorEmail : '';
$this->content = null;
return $this;
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @covers tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class CoversTag extends SeeTag
{
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag\VersionTag;
/**
* Reflection class for a @deprecated tag in a Docblock.
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class DeprecatedTag extends VersionTag
{
}

View File

@@ -0,0 +1,156 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @example tag in a Docblock.
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ExampleTag extends SourceTag
{
/**
* @var string Path to a file to use as an example.
* May also be an absolute URI.
*/
protected $filePath = '';
/**
* @var bool Whether the file path component represents an URI.
* This determines how the file portion appears at {@link getContent()}.
*/
protected $isURI = false;
/**
* {@inheritdoc}
*/
public function getContent()
{
if (null === $this->content) {
$filePath = '';
if ($this->isURI) {
if (false === strpos($this->filePath, ':')) {
$filePath = str_replace(
'%2F',
'/',
rawurlencode($this->filePath)
);
} else {
$filePath = $this->filePath;
}
} else {
$filePath = '"' . $this->filePath . '"';
}
$this->content = $filePath . ' ' . parent::getContent();
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
Tag::setContent($content);
if (preg_match(
'/^
# File component
(?:
# File path in quotes
\"([^\"]+)\"
|
# File URI
(\S+)
)
# Remaining content (parsed by SourceTag)
(?:\s+(.*))?
$/sux',
$this->description,
$matches
)) {
if ('' !== $matches[1]) {
$this->setFilePath($matches[1]);
} else {
$this->setFileURI($matches[2]);
}
if (isset($matches[3])) {
parent::setContent($matches[3]);
} else {
$this->setDescription('');
}
$this->content = $content;
}
return $this;
}
/**
* Returns the file path.
*
* @return string Path to a file to use as an example.
* May also be an absolute URI.
*/
public function getFilePath()
{
return $this->filePath;
}
/**
* Sets the file path.
*
* @param string $filePath The new file path to use for the example.
*
* @return $this
*/
public function setFilePath($filePath)
{
$this->isURI = false;
$this->filePath = trim($filePath);
$this->content = null;
return $this;
}
/**
* Sets the file path as an URI.
*
* This function is equivalent to {@link setFilePath()}, except that it
* convers an URI to a file path before that.
*
* There is no getFileURI(), as {@link getFilePath()} is compatible.
*
* @param type $uri The new file URI to use as an example.
*/
public function setFileURI($uri)
{
$this->isURI = true;
if (false === strpos($uri, ':')) {
//Relative URL
$this->filePath = rawurldecode(
str_replace(array('/', '\\'), '%2F', $uri)
);
} else {
//Absolute URL or URI.
$this->filePath = $uri;
}
$this->content = null;
return $this;
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Ben Selby <benmatselby@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @link tag in a Docblock.
*
* @author Ben Selby <benmatselby@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class LinkTag extends Tag
{
/** @var string */
protected $link = '';
/**
* {@inheritdoc}
*/
public function getContent()
{
if (null === $this->content) {
$this->content = "{$this->link} {$this->description}";
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
$parts = preg_split('/\s+/Su', $this->description, 2);
$this->link = $parts[0];
$this->setDescription(isset($parts[1]) ? $parts[1] : $parts[0]);
$this->content = $content;
return $this;
}
/**
* Gets the link
*
* @return string
*/
public function getLink()
{
return $this->link;
}
/**
* Sets the link
*
* @param string $link The link
*
* @return $this
*/
public function setLink($link)
{
$this->link = $link;
$this->content = null;
return $this;
}
}

View File

@@ -0,0 +1,219 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @method in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class MethodTag extends ReturnTag
{
/** @var string */
protected $method_name = '';
/** @var string */
protected $arguments = '';
/** @var bool */
protected $isStatic = false;
/**
* {@inheritdoc}
*/
public function getContent()
{
if (null === $this->content) {
$this->content = '';
if ($this->isStatic) {
$this->content .= 'static ';
}
$this->content .= $this->type .
" {$this->method_name}({$this->arguments}) " .
$this->description;
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
Tag::setContent($content);
// 1. none or more whitespace
// 2. optionally the keyword "static" followed by whitespace
// 3. optionally a word with underscores followed by whitespace : as
// type for the return value
// 4. then optionally a word with underscores followed by () and
// whitespace : as method name as used by phpDocumentor
// 5. then a word with underscores, followed by ( and any character
// until a ) and whitespace : as method name with signature
// 6. any remaining text : as description
if (preg_match(
'/^
# Static keyword
# Declates a static method ONLY if type is also present
(?:
(static)
\s+
)?
# Return type
(?:
(
(?:[\w\|_\\\\]*\$this[\w\|_\\\\]*)
|
(?:
(?:[\w\|_\\\\]+(?:<[\s\S]*>)?)
# array notation
(?:\[\])*
)*
|
(?:\([\s\S]*\))?
)
\s+
)?
# Legacy method name (not captured)
(?:
[\w_]+\(\)\s+
)?
# Method name
([\w\|_\\\\]+)
# Arguments
\(([^\)]*)\)
\s*
# Description
(.*)
$/sux',
$this->description,
$matches
)) {
list(
,
$static,
$this->type,
$this->method_name,
$this->arguments,
$this->description
) = $matches;
if ($static) {
if (!$this->type) {
$this->type = 'static';
} else {
$this->isStatic = true;
}
} else {
if (!$this->type) {
$this->type = 'void';
}
}
$this->parsedDescription = null;
}
return $this;
}
/**
* Sets the name of this method.
*
* @param string $method_name The name of the method.
*
* @return $this
*/
public function setMethodName($method_name)
{
$this->method_name = $method_name;
$this->content = null;
return $this;
}
/**
* Retrieves the method name.
*
* @return string
*/
public function getMethodName()
{
return $this->method_name;
}
/**
* Sets the arguments for this method.
*
* @param string $arguments A comma-separated arguments line.
*
* @return void
*/
public function setArguments($arguments)
{
$this->arguments = $arguments;
$this->content = null;
return $this;
}
/**
* Returns an array containing each argument as array of type and name.
*
* Please note that the argument sub-array may only contain 1 element if no
* type was specified.
*
* @return string[]
*/
public function getArguments()
{
if (empty($this->arguments)) {
return array();
}
$arguments = explode(',', $this->arguments);
foreach ($arguments as $key => $value) {
$arguments[$key] = explode(' ', trim($value));
}
return $arguments;
}
/**
* Checks whether the method tag describes a static method or not.
*
* @return bool TRUE if the method declaration is for a static method, FALSE
* otherwise.
*/
public function isStatic()
{
return $this->isStatic;
}
/**
* Sets a new value for whether the method is static or not.
*
* @param bool $isStatic The new value to set.
*
* @return $this
*/
public function setIsStatic($isStatic)
{
$this->isStatic = $isStatic;
$this->content = null;
return $this;
}
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @param tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ParamTag extends ReturnTag
{
/** @var string */
protected $variableName = '';
/** @var bool determines whether this is a variadic argument */
protected $isVariadic = false;
/**
* {@inheritdoc}
*/
public function getContent()
{
if (null === $this->content) {
$this->content
= "{$this->type} {$this->variableName} {$this->description}";
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
Tag::setContent($content);
$parts = [];
$rest = $this->description;
// parsing generics and closures to detect types
for($pos = 0, $stacks = []; $pos < strlen($rest); $pos++) {
$char = $rest[$pos];
if(in_array($char, ['<', '(', '[', '{'])) {
array_unshift($stacks, $char);
}
if(
($char === '>' && isset($stacks[0]) && $stacks[0] === '<')
|| ($char === ')' && isset($stacks[0]) && $stacks[0] === '(')
|| ($char === ']' && isset($stacks[0]) && $stacks[0] === '[')
|| ($char === '}' && isset($stacks[0]) && $stacks[0] === '{')
) {
array_shift($stacks);
}
if(!$stacks && preg_match('/\A(\s+)(.*)/su', substr($rest, $pos), $matches)) {
$parts[0] = substr($rest, 0, $pos);
$parts[1] = $matches[1];
$rest = $matches[2];
break;
}
}
array_push($parts, ...preg_split('/(\s+)/u', $rest, 2, PREG_SPLIT_DELIM_CAPTURE));
// if the first item that is encountered is not a variable; it is a type
if (isset($parts[0])
&& (strlen($parts[0]) > 0)
&& ($parts[0][0] !== '$')
) {
$this->type = array_shift($parts);
array_shift($parts);
}
// if the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0])
&& (strlen($parts[0]) > 0)
&& ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')
) {
$this->variableName = array_shift($parts);
array_shift($parts);
if (substr($this->variableName, 0, 3) === '...') {
$this->isVariadic = true;
$this->variableName = substr($this->variableName, 3);
}
}
$this->setDescription(implode('', $parts));
$this->content = $content;
return $this;
}
/**
* Returns the variable's name.
*
* @return string
*/
public function getVariableName()
{
return $this->variableName;
}
/**
* Sets the variable's name.
*
* @param string $name The new name for this variable.
*
* @return $this
*/
public function setVariableName($name)
{
$this->variableName = $name;
$this->content = null;
return $this;
}
/**
* Returns whether this tag is variadic.
*
* @return boolean
*/
public function isVariadic()
{
return $this->isVariadic;
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @property-read tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class PropertyReadTag extends PropertyTag
{
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @property tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class PropertyTag extends ParamTag
{
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @property-write tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class PropertyWriteTag extends PropertyTag
{
}

View File

@@ -0,0 +1,129 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Type\Collection;
/**
* Reflection class for a @return tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ReturnTag extends Tag
{
/** @var string The raw type component. */
protected $type = '';
/** @var Collection The parsed type component. */
protected $types = null;
/**
* {@inheritdoc}
*/
public function getContent()
{
if (null === $this->content) {
$this->content = "{$this->getType()} {$this->description}";
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
$parts = preg_split('/(?<!,)\s+/Su', $this->description, 2);
// any output is considered a type
$this->type = $parts[0];
$this->types = null;
$this->setDescription(isset($parts[1]) ? $parts[1] : '');
$this->content = $content;
return $this;
}
/**
* Returns the unique types of the variable.
*
* @return string[]
*/
public function getTypes()
{
return $this->getTypesCollection()->getArrayCopy();
}
/**
* Returns the type section of the variable.
*
* @return string
*/
public function getType()
{
return (string) $this->getTypesCollection();
}
/**
* Set the type section of the variable
*
* @param string $type
* @return $this
*/
public function setType($type)
{
$this->type = $type;
$this->types = null;
$this->content = null;
return $this;
}
/**
* Add a type to the type section of the variable
*
* @param string $type
* @return $this
*/
public function addType($type)
{
$this->type = $this->type . Collection::OPERATOR_OR . $type;
$this->types = null;
$this->content = null;
return $this;
}
/**
* Returns the type collection.
*
* @return void
*/
protected function getTypesCollection()
{
if (null === $this->types) {
$this->types = new Collection(
array($this->type),
$this->docblock ? $this->docblock->getContext() : null,
$this->docblock ? $this->docblock->getGenerics() : array()
);
}
return $this->types;
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @see tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class SeeTag extends Tag
{
/** @var string */
protected $refers = null;
/**
* {@inheritdoc}
*/
public function getContent()
{
if (null === $this->content) {
$this->content = "{$this->refers} {$this->description}";
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
$parts = preg_split('/\s+/Su', $this->description, 2);
// any output is considered a type
$this->refers = $parts[0];
$this->setDescription(isset($parts[1]) ? $parts[1] : '');
$this->content = $content;
return $this;
}
/**
* Gets the structural element this tag refers to.
*
* @return string
*/
public function getReference()
{
return $this->refers;
}
/**
* Sets the structural element this tag refers to.
*
* @param string $refers The new type this tag refers to.
*
* @return $this
*/
public function setReference($refers)
{
$this->refers = $refers;
$this->content = null;
return $this;
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag\VersionTag;
/**
* Reflection class for a @since tag in a Docblock.
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class SinceTag extends VersionTag
{
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @source tag in a Docblock.
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class SourceTag extends Tag
{
/**
* @var int The starting line, relative to the structural element's
* location.
*/
protected $startingLine = 1;
/**
* @var int|null The number of lines, relative to the starting line. NULL
* means "to the end".
*/
protected $lineCount = null;
/**
* {@inheritdoc}
*/
public function getContent()
{
if (null === $this->content) {
$this->content
= "{$this->startingLine} {$this->lineCount} {$this->description}";
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
if (preg_match(
'/^
# Starting line
([1-9]\d*)
\s*
# Number of lines
(?:
((?1))
\s+
)?
# Description
(.*)
$/sux',
$this->description,
$matches
)) {
$this->startingLine = (int)$matches[1];
if (isset($matches[2]) && '' !== $matches[2]) {
$this->lineCount = (int)$matches[2];
}
$this->setDescription($matches[3]);
$this->content = $content;
}
return $this;
}
/**
* Gets the starting line.
*
* @return int The starting line, relative to the structural element's
* location.
*/
public function getStartingLine()
{
return $this->startingLine;
}
/**
* Sets the starting line.
*
* @param int $startingLine The new starting line, relative to the
* structural element's location.
*
* @return $this
*/
public function setStartingLine($startingLine)
{
$this->startingLine = $startingLine;
$this->content = null;
return $this;
}
/**
* Returns the number of lines.
*
* @return int|null The number of lines, relative to the starting line. NULL
* means "to the end".
*/
public function getLineCount()
{
return $this->lineCount;
}
/**
* Sets the number of lines.
*
* @param int|null $lineCount The new number of lines, relative to the
* starting line. NULL means "to the end".
*
* @return $this
*/
public function setLineCount($lineCount)
{
$this->lineCount = $lineCount;
$this->content = null;
return $this;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Andrew Smith <espadav8@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @SuppressWarnings tag in a Docblock.
*
* @author Andrew Smith <espadav8@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class SuppressWarningsTag extends Tag
{
public function __toString()
{
return "@{$this->getName()}{$this->getContent()}";
}
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @template tag in a Docblock.
*
* @author chack1172 <chack1172@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class TemplateTag extends ParamTag
{
/** @var string */
protected $templateName = null;
/** @var string|null */
protected $bound = null;
public function getContent()
{
if (null === $this->content) {
$this->content = $this->templateName;
if (null !== $this->bound) {
$this->content .= ' of ' . $this->bound;
}
}
return $this->content;
}
/**
* {@inheritDoc}
*/
public function setContent($content)
{
$parts = explode(' of ', $content);
$this->templateName = $parts[0];
if (isset($parts[1])) {
$this->bound = $parts[1];
}
$this->setDescription('');
$this->content = $content;
return $this;
}
/**
* Gets the template name
*
* @return string
*/
public function getTemplateName()
{
return $this->templateName;
}
/**
* Sets the template name
*
* @param string $templateName
*
* @return $this
*/
public function setTemplateName($templateName)
{
$this->templateName = $templateName;
$this->content = null;
return $this;
}
/**
* Gets the bound type
*
* @return string|null
*/
public function getBound()
{
return $this->bound;
}
/**
* Sets the bound type
* @param string|null $bound
* @return $this
*/
public function setBound($bound)
{
$this->bound = $bound;
$this->content = null;
return $this;
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @throws tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ThrowsTag extends ReturnTag
{
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @uses tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class UsesTag extends SeeTag
{
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @var tag in a Docblock.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class VarTag extends ParamTag
{
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @version tag in a Docblock.
*
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class VersionTag extends Tag
{
/**
* PCRE regular expression matching a version vector.
* Assumes the "x" modifier.
*/
const REGEX_VECTOR = '(?:
# Normal release vectors.
\d\S*
|
# VCS version vectors. Per PHPCS, they are expected to
# follow the form of the VCS name, followed by ":", followed
# by the version vector itself.
# By convention, popular VCSes like CVS, SVN and GIT use "$"
# around the actual version vector.
[^\s\:]+\:\s*\$[^\$]+\$
)';
/** @var string The version vector. */
protected $version = '';
public function getContent()
{
if (null === $this->content) {
$this->content = "{$this->version} {$this->description}";
}
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
if (preg_match(
'/^
# The version vector
(' . self::REGEX_VECTOR . ')
\s*
# The description
(.+)?
$/sux',
$this->description,
$matches
)) {
$this->version = $matches[1];
$this->setDescription(isset($matches[2]) ? $matches[2] : '');
$this->content = $content;
}
return $this;
}
/**
* Gets the version section of the tag.
*
* @return string The version section of the tag.
*/
public function getVersion()
{
return $this->version;
}
/**
* Sets the version section of the tag.
*
* @param string $version The new version section of the tag.
* An invalid value will set an empty string.
*
* @return $this
*/
public function setVersion($version)
{
$this->version
= preg_match('/^' . self::REGEX_VECTOR . '$/ux', $version)
? $version
: '';
$this->content = null;
return $this;
}
}

View File

@@ -0,0 +1,327 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Type;
use Barryvdh\Reflection\DocBlock\Context;
/**
* Collection
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class Collection extends \ArrayObject
{
/** @var string Definition of the OR operator for types */
const OPERATOR_OR = '|';
/** @var string Definition of the ARRAY operator for types */
const OPERATOR_ARRAY = '[]';
/** @var string Definition of the NAMESPACE operator in PHP */
const OPERATOR_NAMESPACE = '\\';
/** @var string[] List of recognized keywords */
protected static $keywords = array(
'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double',
'object', 'mixed', 'array', 'resource', 'void', 'null', 'scalar',
'callback', 'callable', 'false', 'true', 'self', '$this', 'static',
'array-key', 'number', 'iterable', 'pure-callable', 'closed-resource',
'open-resource', 'positive-int', 'negative-int', 'non-positive-int',
'non-negative-int', 'non-zero-int', 'non-empty-array', 'list',
'non-empty-list', 'key-of', 'value-of', 'template-type', 'class-string',
'callable-string', 'numeric-string', 'non-empty-string',
'non-falsy-string', 'literal-string', 'lowercase-string', 'never',
'never-return', 'never-returns', 'no-return', 'int-mask', 'int-mask-of'
);
/**
* Current invoking location.
*
* This is used to prepend to type with a relative location.
* May also be 'default' or 'global', in which case they are ignored.
*
* @var Context
*/
protected $context = null;
/**
* List of generics types
*
* @var string[]
*/
protected $generics = array();
/**
* Registers the namespace and aliases; uses that to add and expand the
* given types.
*
* @param string[] $types Array containing a list of types to add to this
* container.
* @param Context $location The current invoking location.
*/
public function __construct(
array $types = array(),
?Context $context = null,
array $generics = array()
) {
$this->context = null === $context ? new Context() : $context;
$this->generics = array_merge($this->context->getGenerics(), $generics);
foreach ($types as $type) {
$this->add($type);
}
}
/**
* Returns the current invoking location.
*
* @return Context
*/
public function getContext()
{
return $this->context;
}
/**
* Adds a new type to the collection and expands it if it contains a
* relative namespace.
*
* If a class in the type contains a relative namespace than this collection
* will try to expand that into a FQCN.
*
* @param string $type A 'Type' as defined in the phpDocumentor
* documentation.
*
* @throws \InvalidArgumentException if a non-string argument is passed.
*
* @see http://phpdoc.org/docs/latest/for-users/types.html for the
* definition of a type.
*
* @return void
*/
public function add($type)
{
if (!is_string($type)) {
throw new \InvalidArgumentException(
'A type should be represented by a string, received: '
.var_export($type, true)
);
}
// separate the type by the OR operator
$type_parts = $this->explode($type);
foreach ($type_parts as $part) {
$expanded_type = $this->expand($part);
if ($expanded_type) {
$this[] = $expanded_type;
}
}
}
/**
* Returns a string representation of the collection.
*
* @return string The resolved types across the collection, separated with
* {@link self::OPERATOR_OR}.
*/
public function __toString()
{
return implode(self::OPERATOR_OR, $this->getArrayCopy());
}
/**
* Analyzes the given union of types and returns separated by OR operator
* single types.
*
* @param string $type The type or union of types
*
* @return array
*/
protected function explode($type)
{
$type_parts = [];
$curr_type = '';
$nest_level = 0;
foreach (str_split($type) as $char) {
if ($char === self::OPERATOR_OR && $nest_level === 0) {
$type_parts[] = $curr_type;
$curr_type = '';
} else {
if (in_array($char, ['<', '(', '[', '{'])) {
$nest_level++;
} else if (in_array($char, ['>', ')', ']', '}'])) {
$nest_level--;
}
$curr_type .= $char;
}
}
$type_parts[] = $curr_type;
return $type_parts;
}
/**
* Analyzes the given type and returns the FQCN variant.
*
* When a type is provided this method checks whether it is not a keyword or
* Fully Qualified Class Name. If so it will use the given namespace and
* aliases to expand the type to a FQCN representation.
*
* This method only works as expected if the namespace and aliases are set;
* no dynamic reflection is being performed here.
*
* @param string $type The relative or absolute type.
*
* @uses getNamespace to determine with what to prefix the type name.
* @uses getNamespaceAliases to check whether the first part of the relative
* type name should not be replaced with another namespace.
*
* @return string
*/
protected function expand($type)
{
$type = trim($type);
if (!$type) {
return '';
}
// Check for generics values and array shapes
if (preg_match('/^[\w-]+(<.+>|\[.+\]|{.+})$/', $type)) {
return $type;
}
// Check for callable types
if (preg_match('/\(.*?(?=\:)/', $type)) {
return $type;
}
if($type[0] === '(') {
return $type;
}
// Literal strings
if ($type[0] === '"' || $type[0] === "'") {
return $type;
}
if ($this->isTypeAnArray($type)) {
return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
}
if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type) && !$this->isTypeAGeneric($type)) {
if($this->shouldBeAbsolute($type)){
return self::OPERATOR_NAMESPACE . $type;
}
$type_parts = explode(self::OPERATOR_NAMESPACE, $type, 2);
$namespace_aliases = $this->context->getNamespaceAliases();
// if the first segment is not an alias; prepend namespace name and
// return
if (!isset($namespace_aliases[$type_parts[0]]) &&
!isset($namespace_aliases[strstr($type_parts[0], '::', true)])) {
$namespace = $this->context->getNamespace();
if ('' !== $namespace) {
$namespace .= self::OPERATOR_NAMESPACE;
}
return self::OPERATOR_NAMESPACE . $namespace . $type;
}
if (strpos($type_parts[0], '::')) {
$type_parts[] = strstr($type_parts[0], '::');
$type_parts[0] = $namespace_aliases[strstr($type_parts[0], '::', true)];
return implode('', $type_parts);
}
$type_parts[0] = $namespace_aliases[$type_parts[0]];
$type = implode(self::OPERATOR_NAMESPACE, $type_parts);
}
return $type;
}
/**
* Detects whether the given type represents an array.
*
* @param string $type A relative or absolute type as defined in the
* phpDocumentor documentation.
*
* @return bool
*/
protected function isTypeAnArray($type)
{
return substr($type, -2) === self::OPERATOR_ARRAY;
}
/**
* Detects whether the given type represents a PHPDoc keyword.
*
* @param string $type A relative or absolute type as defined in the
* phpDocumentor documentation.
*
* @return bool
*/
protected function isTypeAKeyword($type)
{
return in_array(strtolower($type), static::$keywords, true);
}
/**
* Detects whether the given type represents a relative or absolute path.
*
* This method will detect keywords as being absolute; even though they are
* not preceeded by a namespace separator.
*
* @param string $type A relative or absolute type as defined in the
* phpDocumentor documentation.
*
* @return bool
*/
protected function isRelativeType($type)
{
return ($type[0] !== self::OPERATOR_NAMESPACE)
|| $this->isTypeAKeyword($type);
}
/**
* Detects whether the given type represents a generic.
*
* @param string $type A relative or absolute type as defined in the
* phpDocumentor documentation.
*
* @return bool
*/
protected function isTypeAGeneric($type)
{
return in_array($type, $this->generics, true);
}
/**
* Detects if the type should actually be absolute, by checking if it exists.
*
* @param string $type A relative or absolute type as defined in the
* phpDocumentor documentation.
*
* @return bool
*/
protected function shouldBeAbsolute($type){
return class_exists($type);
}
}