Skip to content

Commit a34f6df

Browse files
committed
Add basic documentation for API
1 parent ede722f commit a34f6df

9 files changed

+229
-1
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Parser Reflection API Library
33

44
Parser Reflection API library provides a set of classes that extend original internal Reflection classes, but powered by [PHP-Parser](https://github.com/nikic/PHP-Parser) library thus allowing to create a reflection instance without loading classes into the memory.
55

6-
This library can be used for analysing the source code, automatic proxy creation and much more.
6+
This library can be used for analysing the source code for PHP versions 5.5, 5.6, 7.0; for automatic proxy creation and much more.
77

88
[![Build Status](https://scrutinizer-ci.com/g/goaop/parser-reflection/badges/build.png?b=master)](https://scrutinizer-ci.com/g/goaop/parser-reflection/build-status/master)
99
[![Code Coverage](https://scrutinizer-ci.com/g/goaop/parser-reflection/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/goaop/parser-reflection/?branch=master)
@@ -31,6 +31,14 @@ Just use `Go\ParserReflection` package reflection classes like traditional ones:
3131
$parsedClass = new \Go\ParserReflection\ReflectionClass(SomeClass::class);
3232
var_dump($parsedClass->getMethods());
3333
```
34+
Or you can use an additional classes [`ReflectionFile`][0] and [`ReflectionFileNamespace`][1] to analyse a raw PHP files
35+
36+
```php
37+
$parsedFile = new \Go\ParserReflection\ReflectionFile('SomeClass.php');
38+
$fileNameSpaces = $parsedFile->getFileNamespaces()
39+
var_dump($fileNameSpaces);
40+
var_dump($fileNameSpaces[0]->getClass(SomeClass::class)->getMethods();
41+
```
3442

3543
How it works?
3644
------------
@@ -48,3 +56,6 @@ Compatibility
4856
------------
4957

5058
All parser reflection classes extend PHP internal reflection classes, this means that you can use `\Go\ParserReflection\ReflectionClass` instance in any place that asks for `\ReflectionClass` instance. All reflection methods should be compatible with original ones, providing an except methods that requires object manipulation, such as `invoke()`, `invokeArgs()`, `setAccessible()`, etc. These methods will trigger the autoloading of class and switching to the internal reflection.
59+
60+
[0]: docs/reflection_file.md
61+
[1]: docs/reflection_file_namespace.md

docs/relection_class.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ReflectionClass
2+
==============
3+
4+
The `ReflectionClass` class reports an information about a class. This class is available in the standard PHP, so for any questions, please look at documentation for [`ReflectionClass`][0]
5+
6+
But be careful, that several methods require the class to be loaded into the memory, otherwise an exception will be thrown.
7+
8+
List of methods, that require class to be loaded
9+
---------
10+
11+
- ReflectionClass::newInstance — Creates a new class instance from given arguments.
12+
- ReflectionClass::newInstanceArgs — Creates a new class instance from given arguments.
13+
- ReflectionClass::newInstanceWithoutConstructor — Creates a new class instance without invoking the constructor.
14+
- ReflectionClass::setStaticPropertyValue — Sets static property value
15+
16+
[0]: http://php.net/manual/en/class.reflectionclass.php

docs/relection_file.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
ReflectionFile
2+
==============
3+
4+
The `ReflectionFile` class reports an information about a file with valid PHP source code. This class is not available in the standard PHP
5+
6+
API
7+
---
8+
9+
```php
10+
class ReflectionFile
11+
{
12+
public function __construct($fileName, $topLevelNodes = null) {}
13+
public function getFileNamespace($namespaceName) {}
14+
public function getFileNamespaces() {}
15+
public function getName() {}
16+
public function hasFileNamespace($namespaceName) {}
17+
}
18+
```
19+
20+
Methods
21+
-------
22+
23+
- `ReflectionFile::__construct($fileName, $topLevelNodes = null)`
24+
25+
Constructs an instance of `ReflectionFile` object for given `fileName`. Can accept custom AST-tree nodes as optional parameter.
26+
27+
- `ReflectionFile::getFileNamespace($namespaceName)`
28+
29+
Returns a [`ReflectionFileNamespace`][0] instance for the specified namespace in a file. If you don't know an exact name of namespace in the file, then use `getFileNamespaces()` method to get a full list of namespaces for inspection.
30+
31+
- `ReflectionFile::getFileNamespaces()`
32+
33+
Returns an array with available namespaces in the file. Each `namespace {}` section will be represented as a single instance of [`ReflectionFileNamespace`][0] in this list.
34+
35+
- `ReflectionFile::getName()`
36+
37+
Returns a string with the name of file
38+
39+
- `ReflectionFile::hasFileNamespace($namespaceName)`
40+
41+
Checks if requested namespace is present in the file or not. Returns `true` if present.
42+
43+
44+
[0]: reflection_file_namespace.md

docs/relection_file_namespace.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
ReflectionFileNamespace
2+
==============
3+
4+
The `ReflectionFileNamespace` class reports an information about a namespace in the single file. This class is not available in the standard PHP
5+
6+
API
7+
---
8+
9+
```php
10+
class ReflectionFileNamespace
11+
{
12+
public function __construct($fileName, $namespaceName, Namespace_ $namespaceNode = null) {}
13+
public function getClass($className) {}
14+
public function getClasses() {}
15+
public function getConstant($constantName) {}
16+
public function getConstants() {}
17+
public function getDocComment() {}
18+
public function getEndLine() {}
19+
public function getFileName() {}
20+
public function getFunction($functionName) {}
21+
public function getFunctions() {}
22+
public function getName() {}
23+
public function getNamespaceAliases() {}
24+
public function getStartLine() {}
25+
public function hasClass($className) {}
26+
public function hasConstant($constantName) {}
27+
public function hasFunction($functionName) {}
28+
}
29+
```
30+
31+
Methods
32+
-------
33+
34+
- `ReflectionFileNamespace::__construct($fileName, $namespaceName, Namespace_ $namespaceNode = null)`
35+
36+
Constructs an instance of `ReflectionFileNamespace` object for given `fileName` and `namespaceName`. Can accept custom `Namespace_` node as optional parameter.
37+
38+
- `ReflectionFileNamespace::getClass($className)`
39+
40+
Returns the concrete [`ReflectionClass`][0] from the file namespace or `false` if there is no such a class in the current namespace
41+
42+
- `ReflectionFileNamespace::getClasses()`
43+
44+
Returns an array with available classes in the namespace. Each class/trait/interface definition will be represented as a single instance of [`ReflectionClass`][0] in this list.
45+
46+
- `ReflectionFileNamespace::getConstant($constantName)`
47+
48+
Returns a value for the constant with name `$constantName` in the file namespace or `false` if there is no such a constant in the current namespace.
49+
50+
- `ReflectionFileNamespace::getConstants()`
51+
52+
Returns an array with all available constants in the namespace.
53+
54+
- `ReflectionFileNamespace::getDocComment()`
55+
56+
Returns a doc-block section for file namespace if present, otherwise `false`
57+
58+
- `ReflectionFileNamespace::getEndLine()`
59+
60+
Returns a end line for the namespace. Be careful, this value is not correct for simple `namespace Name;` definitions.
61+
62+
- `ReflectionFileNamespace::getFileName()`
63+
64+
Returns a string with the name of file
65+
66+
- `ReflectionFileNamespace::getFunction($functionName)`
67+
68+
Returns the concrete [`ReflectionFunction`][1] from the file namespace or `false` if there is no such a function in the current namespace
69+
70+
- `ReflectionFileNamespace::getFunctions()`
71+
72+
Returns an array with available functions in the namespace. Each function definition will be represented as a single instance of [`ReflectionFunction`][1] in this list.
73+
74+
- `ReflectionFile::getName()`
75+
76+
Returns a string with the name of current file namespace
77+
78+
- `ReflectionFileNamespace::getNamespaceAliases()`
79+
80+
Returns an array with all imported class namespaces and aliases for them in the current namespace.
81+
82+
- `ReflectionFileNamespace::getStartLine()`
83+
84+
Returns a start line for the namespace.
85+
86+
- `ReflectionFileNamespace::hasClass($className)`
87+
88+
Checks if the requested class is present in the file namespace or not. Returns `true` if present.
89+
90+
- `ReflectionFileNamespace::hasConstant($constantName)`
91+
92+
Checks if the requested constant is present in the file namespace or not. Returns `true` if present.
93+
94+
- `ReflectionFileNamespace::hasFunction($functionName)`
95+
96+
Checks if the requested function is present in the file namespace or not. Returns `true` if present.
97+
98+
[0]: reflection_class.md
99+
[1]: reflection_function.md

docs/relection_function.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ReflectionFunction
2+
==============
3+
4+
The `ReflectionFunction` class reports an information about a function. This class is available in the standard PHP, so for any questions, please look at documentation for [`ReflectionFunction`][0]
5+
6+
But be careful, that several methods require the function to be loaded into the memory, otherwise an exception will be thrown.
7+
8+
List of methods, that require function to be loaded
9+
---------
10+
11+
- ReflectionFunction::getClosure — Returns a dynamically created closure for the function
12+
- ReflectionFunction::invoke — Invokes function
13+
- ReflectionFunction::invokeArgs — Invokes function args
14+
15+
[0]: http://php.net/manual/en/class.reflectionfunction.php

docs/relection_method.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ReflectionMethod
2+
==============
3+
4+
The `ReflectionMethod` class reports an information about a method. This class is available in the standard PHP, so for any questions, please look at documentation for [`ReflectionMethod`][0]
5+
6+
But be careful, that several methods require the method and class to be loaded into the memory, otherwise an exception will be thrown.
7+
8+
List of methods, that require method and a corresponding class to be loaded
9+
---------
10+
11+
- ReflectionMethod::getClosure — Returns a dynamically created closure for the method
12+
- ReflectionMethod::invoke — Invokes method
13+
- ReflectionMethod::invokeArgs — Invokes method args
14+
- ReflectionMethod::setAccessible — Set method accessibility
15+
16+
[0]: http://php.net/manual/en/class.reflectionmethod.php

docs/relection_parameter.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ReflectionParameter
2+
==============
3+
4+
The `ReflectionParameter` class reports an information about an parameter. This class is available in the standard PHP, so for any questions, please look at documentation for [`ReflectionParameter`][0]
5+
6+
[0]: http://php.net/manual/en/class.reflectionparameter.php

docs/relection_property.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ReflectionProperty
2+
==============
3+
4+
The `ReflectionProperty` class reports an information about a property. This class is available in the standard PHP, so for any questions, please look at documentation for [`ReflectionProperty`][0]
5+
6+
But be careful, that several methods require the property and class to be loaded into the memory, otherwise an exception will be thrown.
7+
8+
List of methods, that require property and a corresponding class to be loaded
9+
---------
10+
11+
- ReflectionProperty::setAccessible — Set property accessibility
12+
- ReflectionProperty::setValue — Set property value
13+
14+
15+
[0]: http://php.net/manual/en/class.reflectionproperty.php

docs/relection_type.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ReflectionType
2+
==============
3+
4+
The `ReflectionType` class reports an information about a type. This class is available in the standard PHP, so for any questions, please look at documentation for [`ReflectionType`][0]
5+
6+
[0]: http://php.net/manual/en/class.reflectiontype.php

0 commit comments

Comments
 (0)