type-lang/phpdoc-template-tags

Adds support for template PHPDoc tags

dev-master / 1.0.x-dev 2024-04-17 19:20 UTC

This package is auto-updated.

Last update: 2024-05-17 19:28:34 UTC


README

dark.png?raw=true

PHP 8.1+ Latest Stable Version Latest Unstable Version License MIT

badge.svg

Adds support of the PHPDoc standard DocBlock tags.

Read documentation pages for more information.

Installation

TypeLang PHPDoc Standard Tags is available as Composer repository and can be installed using the following command in a root of your project:

$ composer require type-lang/phpdoc-template-tags

Introduction

Adds support for advanced template annotations.

  • @templateTypeLang\PHPDoc\Template\TemplateTagFactory
  • @template-covariantTypeLang\PHPDoc\Template\TemplateCovariantTagFactory
  • @template-contravariantTypeLang\PHPDoc\Template\TemplateContravariantTagFactory
  • @template-extends (or @extends) — TypeLang\PHPDoc\Template\TemplateExtendsTagFactory
  • @template-implements (or @implements) — TypeLang\PHPDoc\Template\TemplateImplementsTagFactory
  • @template-use (or @use) — TypeLang\PHPDoc\Template\TemplateUseTagFactory

Usage

use TypeLang\PHPDoc\Parser;
use TypeLang\PHPDoc\Template;
use TypeLang\PHPDoc\Tag\Factory\TagFactory;

$tags = new TagFactory();

// Add support of template tags
$tags->register('template', new Template\TemplateTagFactory());
$tags->register('template-covariant', new Template\TemplateCovariantTagFactory());
$tags->register('template-contravariant', new Template\TemplateContravariantTagFactory());
$tags->register(['extends', 'template-extends'], new Template\TemplateExtendsTagFactory());
$tags->register(['implements', 'template-implements'], new Template\TemplateImplementsTagFactory());
$tags->register(['use', 'template-use'], new Template\TemplateUseTagFactory());

$docblock = (new Parser($tags))
    ->parse(<<<'PHPDOC'
        /**
         * @template T of object
         * @template-extends \Traversable<array-key, T>
         */
        PHPDOC);

var_dump($docblock);