gnusocial.rocks/soc/2020/daily_report/archive/app/vendor/php-di/phpdoc-reader
Diogo Peralta Cordeiro 88c194c013 Some initial content 2021-03-28 21:41:35 +01:00
..
src/PhpDocReader Some initial content 2021-03-28 21:41:35 +01:00
LICENSE Some initial content 2021-03-28 21:41:35 +01:00
README.md Some initial content 2021-03-28 21:41:35 +01:00
composer.json Some initial content 2021-03-28 21:41:35 +01:00

README.md

PhpDocReader

Build Status

This project is used by:

Fork the README to add your project here.

Features

PhpDocReader parses @var and @param values in PHP docblocks:


use My\Cache\Backend;

class Cache
{
    /**
     * @var Backend
     */
    protected $backend;

    /**
     * @param Backend $backend
     */
    public function __construct($backend)
    {
    }
}

It supports namespaced class names with the same resolution rules as PHP:

  • fully qualified name (starting with \)
  • imported class name (eg. use My\Cache\Backend;)
  • relative class name (from the current namespace, like SubNamespace\MyClass)
  • aliased class name (eg. use My\Cache\Backend as FooBar;)

Primitive types (@var string) are ignored (returns null), only valid class names are returned.

Usage

$reader = new PhpDocReader();

// Read a property type (@var phpdoc)
$property = new ReflectionProperty($className, $propertyName);
$propertyClass = $reader->getPropertyClass($property);

// Read a parameter type (@param phpdoc)
$parameter = new ReflectionParameter(array($className, $methodName), $parameterName);
$parameterClass = $reader->getParameterClass($parameter);