urban d63a4904f9 trxbot 10 月之前
..
.github d63a4904f9 trxbot 10 月之前
src d63a4904f9 trxbot 10 月之前
.gitattributes d63a4904f9 trxbot 10 月之前
.gitignore d63a4904f9 trxbot 10 月之前
.phpcs.xml.dist d63a4904f9 trxbot 10 月之前
LICENSE d63a4904f9 trxbot 10 月之前
README.md d63a4904f9 trxbot 10 月之前
composer.json d63a4904f9 trxbot 10 月之前

README.md

PhpDocReader

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);