|
1 | | -Reflection [](http://travis-ci.org/phpDocumentor/Reflection) |
| 1 | +[](https://opensource.org/licenses/MIT) |
| 2 | +[](https://travis-ci.org/phpDocumentor/Reflection) |
| 3 | +[](https://ci.appveyor.com/project/phpDocumentor/Reflection/branch/master) |
| 4 | +[](https://coveralls.io/github/phpDocumentor/Reflection?branch=master) |
| 5 | +[](https://scrutinizer-ci.com/g/phpDocumentor/Reflection/?branch=master) |
| 6 | +[](https://scrutinizer-ci.com/g/phpDocumentor/Reflection/?branch=master) |
| 7 | +[](https://packagist.org/packages/phpDocumentor/Reflection) |
| 8 | +[](https://packagist.org/packages/phpDocumentor/Reflection) |
| 9 | + |
| 10 | + |
| 11 | +Reflection |
2 | 12 | ========== |
3 | 13 |
|
4 | | -Reflection library to do Static Analysis for PHP Projects |
| 14 | +Using this library it is possible to statically reflect one or more files and create an object graph representing |
| 15 | +your application's structure, including accompanying in-source documentation using DocBlocks. |
| 16 | + |
| 17 | +The information that this library provides is similar to what the (built-in) Reflection extension of PHP provides; there |
| 18 | +are however several advantages to using this library: |
| 19 | + |
| 20 | +- Due to its Static nature it does not execute procedural code in your reflected files where Dynamic Reflection does. |
| 21 | +- Because the none of the code is interpreted by PHP (and executed) Static Reflection uses less memory. |
| 22 | +- Can reflect complete files |
| 23 | +- Can reflect a whole project by reflecting multiple files. |
| 24 | +- Reflects the contents of a DocBlock instead of just mentioning there is one. |
| 25 | +- Is capable of analyzing code written for any PHP version (starting at 5.2) up to and including your installed |
| 26 | + PHP version. |
| 27 | + |
| 28 | +## Features |
| 29 | + |
| 30 | +* [Creates an object graph] containing the structure of your application much like a site map shows the |
| 31 | + structure of a website. |
| 32 | +* Can read and interpret code of any PHP version starting with 5.2 up to and including your currently installed version |
| 33 | + of PHP. |
| 34 | +* Due it's clean interface it can be in any application without a complex setup. |
| 35 | + |
| 36 | +## Installation |
| 37 | + |
| 38 | +In order to inspect a codebase you need to tell composer to include the `phpdocumentor/reflection` package. This |
| 39 | +can easily be done using the following command in your command line terminal: |
| 40 | + |
| 41 | + composer require "phpdocumentor/reflection: ~4.0" |
| 42 | + |
| 43 | +After the installation is complete no further configuration is necessary and you can immediately start using it. |
| 44 | + |
| 45 | +## Basic Usage |
| 46 | + |
| 47 | +This Reflection library uses [PSR-4] and it is recommended to use a PSR-4 compatible autoloader to load all the |
| 48 | +files containing the classes for this library. |
| 49 | + |
| 50 | +An easy way to do this is by including the [composer] autoloader as shown here: |
| 51 | + |
| 52 | + include 'vendor/autoload.php'; |
| 53 | + |
| 54 | +Once that is done you can use the `createInstance()` method of the `\phpDocumentor\Reflection\Php\ProjectFactory` class to instantiate a new project factory and |
| 55 | +pre-configure it with sensible defaults. Optional you can specify the parser version that shall be used as an argument of `createInstance()`. |
| 56 | +By default the php7 parser is prefered. And php5 is used as a fallback. See the [documentation of phpparser] for more info. |
| 57 | + |
| 58 | + $projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance(); |
| 59 | + |
| 60 | +At this point we are ready to analyze your complete project or just one file at the time. Just pass an array of file paths to the `create` method of the project factory. |
| 61 | + |
| 62 | + $projectFiles = [new \phpDocumentor\Reflection\File\LocalFile('tests/example.file.php')]; |
| 63 | + $project = $projectFactory->create('My Project', $projectFiles); |
| 64 | + |
| 65 | +When the process is ready a new object of type `phpDocumentor\Reflection\Php\Project` will be returned that |
| 66 | +contains a complete hierarchy of all files with their classes, traits and interfaces (and everything in there), but also |
| 67 | +all namespaces and packages as a hierarchical tree. |
| 68 | + |
| 69 | +> See the [example] script for a detailed and commented example |
| 70 | +
|
| 71 | +[Build Status]: https://secure.travis-ci.org/phpDocumentor/Reflection.png |
| 72 | +[PSR-4]: http://php-fig.com |
| 73 | +[example]: example.php |
| 74 | +[composer]: http://getcomposer.org |
| 75 | +[documentation of phpparser]: https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-2.0.md#creating-a-parser-instance |
0 commit comments