Skip to content

Commit da27bc2

Browse files
committed
Merge pull request #76 from jaapio/feature/documentation
Feature/documentation
2 parents 47097d3 + 5a992cb commit da27bc2

File tree

3 files changed

+20
-86
lines changed

3 files changed

+20
-86
lines changed

README.md

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ are however several advantages to using this library:
2222

2323
* [Creates an object graph] containing the structure of your application much like a site map shows the
2424
structure of a website.
25-
* Supports [incrementally updating] a previously analyzed codebase by caching the results
26-
and checking if any of the files have changed.
27-
* Can [filter] the object graph, for example to hide specific elements.
28-
* You can inspect your object graph, analyze it and report any errors and inconsistencies found using [validators].
2925
* Can read and interpret code of any PHP version starting with 5.2 up to and including your currently installed version
3026
of PHP.
31-
* Can be integrated into Silex and Cilex using a [Service Provider].
27+
* Due it's clean interface it can be in any application without a complex setup.
3228

3329
## Installation
3430

@@ -41,49 +37,30 @@ After the installation is complete no further configuration is necessary and you
4137

4238
## Basic Usage
4339

44-
This Reflection library uses [PSR-0] and it is recommended to use a PSR-0 compatible autoloader to load all the
40+
This Reflection library uses [PSR-4] and it is recommended to use a PSR-4 compatible autoloader to load all the
4541
files containing the classes for this library.
4642

4743
An easy way to do this is by including the [composer] autoloader as shown here:
4844

4945
include 'vendor/autoload.php';
5046

51-
Once that is done you can use the `create()` method of the `Analyzer` class to instantiate your source Analyzer and
47+
Once that is done you can use the `createIntance()` method of the `\phpDocumentor\Reflection\Php\ProjectFactory` class to instantiate a new project factory and
5248
pre-configure it with sensible defaults.
5349

54-
$analyzer = phpDocumentor\Reflection\Php\Analyzer::create();
50+
$projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance();
5551

56-
At this point we are ready to analyze files, one at a time. By loading the file using an `SplFileObject` class and
57-
feeding that to the `analyze` of the `Analyzer` method we convert the PHP code in that file into an object of type
58-
`phpDocumentor\Reflection\Php\File`.
52+
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.
5953

60-
This object describing a file is returned to us but also added to another object that describes your entire project.
54+
$projectFiles = ['tests/example.file.php'];
55+
$project = $projectFactory->create('My Project', $projectFiles);
6156

62-
$splFileObject = new \SplFileObject('tests/example.file.php');
63-
$analyzer->analyze($splFileObject);
64-
65-
The step above can be repeated for as many files as you have. When you are done you will have to call the finalize
66-
method of the analyzer. This method will do another analysis pass. This pass will connect the dots and do any processing
67-
that relies the structure to be complete, such as adding linkage between all elements.
68-
69-
When the finalization is ready a new object of type `phpDocumentor\Reflection\Php\Project` will be returned that
70-
contains a complete hierarchy of all files with their classes, traits and interfaces (and everything in there), but also
71-
all namespaces and packages as a hierarchical tree.
72-
73-
$project = $analyzer->finalize();
74-
75-
When the finalization is ready a new object of type `phpDocumentor\Reflection\Php\Project` will be returned that
57+
When the process is ready a new object of type `phpDocumentor\Reflection\Php\Project` will be returned that
7658
contains a complete hierarchy of all files with their classes, traits and interfaces (and everything in there), but also
7759
all namespaces and packages as a hierarchical tree.
7860

7961
> See the [example] script for a detailed and commented example
8062
8163
[Build Status]: https://secure.travis-ci.org/phpDocumentor/Reflection.png
82-
[PSR-0]: http://php-fig.com
83-
[Creates an object graph]: docs/usage.rst
84-
[incrementally updating]: docs/incremental-updates.rst
85-
[filter]: docs/filtering.rst
86-
[validators]: docs/inspecting.rst
87-
[Service Provider]: docs/integrating-with-silex-and-cilex.rst
64+
[PSR-4]: http://php-fig.com
8865
[example]: example.php
8966
[composer]: http://getcomposer.org

TODO

Lines changed: 0 additions & 41 deletions
This file was deleted.

example.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,24 @@
1414
*/
1515

1616
// use Composer's autoloader to allow the application to automatically load all classes on request.
17+
use phpDocumentor\Reflection\Php\Project;
18+
1719
include 'vendor/autoload.php';
1820

1921
// Create a new Analyzer with which we can analyze a PHP source file
20-
$analyzer = phpDocumentor\Descriptor\Analyzer::create();
21-
22-
// Load a file that is to be analyzed
23-
$splFileObject = new \SplFileObject('tests/example.file.php');
22+
$projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance();
2423

25-
// Analyze the given file, this will return a the structure of a single file as a
26-
// `\phpDocumentor\Descriptor\File` class and populate a project descriptor object in the Analyzer.
27-
$analyzer->analyze($splFileObject);
24+
// Create an array of files to analize.
25+
$files = ['tests/example.file.php'];
2826

29-
// The returned Project object is of class `phpDocumentor\Descriptor\Project`, see its DocBlock for more
30-
// information on it.
31-
$project = $analyzer->finalize();
27+
//create a new project 'MyProject' containing all elements in the files.
28+
/** @var Project $project */
29+
$project = $projectFactory->create('MyProject', $files);
3230

3331
// As an example of what you can do, let's list all class names in the file 'tests/example.file.php'.
3432
echo 'List all classes in the example source file: ' . PHP_EOL;
3533

36-
/** @var \phpDocumentor\Descriptor\Class_ $class */
37-
foreach ($project->getFiles()->get('tests/example.file.php')->getClasses() as $class) {
38-
echo '- ' . $class->getFullyQualifiedStructuralElementName() . PHP_EOL;
34+
/** @var \phpDocumentor\Reflection\Php\Class_ $class */
35+
foreach ($project->getFiles()['tests/example.file.php']->getClasses() as $class) {
36+
echo '- ' . $class->getFqsen() . PHP_EOL;
3937
}

0 commit comments

Comments
 (0)