https://github.com/php-di/phpdocreader
Read @var and @param annotations in phpdoc blocks
https://github.com/php-di/phpdocreader
Last synced: about 1 month ago
JSON representation
Read @var and @param annotations in phpdoc blocks
- Host: GitHub
- URL: https://github.com/php-di/phpdocreader
- Owner: PHP-DI
- License: mit
- Created: 2013-09-24T14:44:26.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-06-30T13:12:52.000Z (almost 4 years ago)
- Last Synced: 2025-03-29T10:06:31.343Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 82 KB
- Stars: 73
- Watchers: 3
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PhpDocReader

[](https://github.com/PHP-DI/PhpDocReader/actions/workflows/ci.yml)This project is used by:
- [PHP-DI 6](http://php-di.org/)
- [Woohoo Labs. Zen](https://github.com/woohoolabs/zen)Fork the README to add your project here.
## Features
PhpDocReader parses `@var` and `@param` values in PHP docblocks:
```php
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
```php
$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([$className, $methodName], $parameterName);
$parameterClass = $reader->getParameterClass($parameter);
```