mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Introduce a Simple implementation of the TagFactory interface
Less complex interface to implement makes it easier to implement tag factories as they are part of the new behavior of the StandardTagFactory.
This commit is contained in:
@@ -47,13 +47,13 @@ use const PREG_SPLIT_DELIM_CAPTURE;
|
|||||||
*/
|
*/
|
||||||
class DescriptionFactory
|
class DescriptionFactory
|
||||||
{
|
{
|
||||||
/** @var TagFactory */
|
/** @var SimpleTagFactory */
|
||||||
private $tagFactory;
|
private $tagFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this factory with the means to construct (inline) tags.
|
* Initializes this factory with the means to construct (inline) tags.
|
||||||
*/
|
*/
|
||||||
public function __construct(TagFactory $tagFactory)
|
public function __construct(SimpleTagFactory $tagFactory)
|
||||||
{
|
{
|
||||||
$this->tagFactory = $tagFactory;
|
$this->tagFactory = $tagFactory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?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 phpDocumentor\Reflection\DocBlock;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||||
|
|
||||||
|
interface SimpleTagFactory
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method responsible for instantiating the correct sub type.
|
||||||
|
*
|
||||||
|
* @param string $tagLine The text for this tag, including description.
|
||||||
|
*
|
||||||
|
* @return Tag A new tag object.
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException If an invalid tag line was presented.
|
||||||
|
*/
|
||||||
|
public function create(string $tagLine, ?TypeContext $context = null): Tag;
|
||||||
|
}
|
||||||
@@ -233,7 +233,7 @@ final class StandardTagFactory implements TagFactory
|
|||||||
/**
|
/**
|
||||||
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
|
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
|
||||||
*
|
*
|
||||||
* @return class-string<Tag>|TagFactory
|
* @return class-string<Tag>|SimpleTagFactory
|
||||||
*/
|
*/
|
||||||
private function findHandlerClassName(string $tagName, TypeContext $context)
|
private function findHandlerClassName(string $tagName, TypeContext $context)
|
||||||
{
|
{
|
||||||
@@ -297,7 +297,7 @@ final class StandardTagFactory implements TagFactory
|
|||||||
* Retrieves a series of ReflectionParameter objects for the static 'create' method of the given
|
* Retrieves a series of ReflectionParameter objects for the static 'create' method of the given
|
||||||
* tag handler class name.
|
* tag handler class name.
|
||||||
*
|
*
|
||||||
* @param class-string|TagFactory $handler
|
* @param class-string|SimpleTagFactory $handler
|
||||||
*
|
*
|
||||||
* @return ReflectionParameter[]
|
* @return ReflectionParameter[]
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace phpDocumentor\Reflection\DocBlock;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||||
|
|
||||||
interface TagFactory
|
interface TagFactory extends SimpleTagFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Adds a parameter to the service locator that can be injected in a tag's factory method.
|
* Adds a parameter to the service locator that can be injected in a tag's factory method.
|
||||||
@@ -40,17 +40,6 @@ interface TagFactory
|
|||||||
*/
|
*/
|
||||||
public function addParameter(string $name, $value): void;
|
public function addParameter(string $name, $value): void;
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method responsible for instantiating the correct sub type.
|
|
||||||
*
|
|
||||||
* @param string $tagLine The text for this tag, including description.
|
|
||||||
*
|
|
||||||
* @return Tag A new tag object.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If an invalid tag line was presented.
|
|
||||||
*/
|
|
||||||
public function create(string $tagLine, ?TypeContext $context = null): Tag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a service with the Service Locator using the FQCN of the class or the alias, if provided.
|
* Registers a service with the Service Locator using the FQCN of the class or the alias, if provided.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\DocBlock\SimpleTagFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||||
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
|
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
|
||||||
@@ -31,7 +32,7 @@ use PHPStan\PhpDocParser\Parser\TypeParser;
|
|||||||
*
|
*
|
||||||
* @internal This class is not part of the BC promise of this library.
|
* @internal This class is not part of the BC promise of this library.
|
||||||
*/
|
*/
|
||||||
class AbstractPHPStanFactory implements TagFactory
|
class AbstractPHPStanFactory implements SimpleTagFactory
|
||||||
{
|
{
|
||||||
private PhpDocParser $parser;
|
private PhpDocParser $parser;
|
||||||
private Lexer $lexer;
|
private Lexer $lexer;
|
||||||
@@ -45,11 +46,6 @@ class AbstractPHPStanFactory implements TagFactory
|
|||||||
$this->factories = $factories;
|
$this->factories = $factories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addParameter(string $name, $value): void
|
|
||||||
{
|
|
||||||
// TODO: Implement addParameter() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create(string $tagLine, ?TypeContext $context = null): Tag
|
public function create(string $tagLine, ?TypeContext $context = null): Tag
|
||||||
{
|
{
|
||||||
$tokens = $this->lexer->tokenize($tagLine);
|
$tokens = $this->lexer->tokenize($tagLine);
|
||||||
@@ -66,14 +62,4 @@ class AbstractPHPStanFactory implements TagFactory
|
|||||||
(string) $ast->value
|
(string) $ast->value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addService(object $service): void
|
|
||||||
{
|
|
||||||
// TODO: Implement addService() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public function registerTagHandler(string $tagName, string $handler): void
|
|
||||||
{
|
|
||||||
// TODO: Implement registerTagHandler() method.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace phpDocumentor\Reflection;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\SimpleTagFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
|
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||||
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
||||||
@@ -41,13 +42,13 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||||||
/** @var DocBlock\DescriptionFactory */
|
/** @var DocBlock\DescriptionFactory */
|
||||||
private $descriptionFactory;
|
private $descriptionFactory;
|
||||||
|
|
||||||
/** @var DocBlock\TagFactory */
|
/** @var DocBlock\SimpleTagFactory */
|
||||||
private $tagFactory;
|
private $tagFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this factory with the required subcontractors.
|
* Initializes this factory with the required subcontractors.
|
||||||
*/
|
*/
|
||||||
public function __construct(DescriptionFactory $descriptionFactory, TagFactory $tagFactory)
|
public function __construct(DescriptionFactory $descriptionFactory, SimpleTagFactory $tagFactory)
|
||||||
{
|
{
|
||||||
$this->descriptionFactory = $descriptionFactory;
|
$this->descriptionFactory = $descriptionFactory;
|
||||||
$this->tagFactory = $tagFactory;
|
$this->tagFactory = $tagFactory;
|
||||||
|
|||||||
Reference in New Issue
Block a user