Skip to content

Commit

Permalink
Add basic documentation for API
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Feb 15, 2016
1 parent ede722f commit a34f6df
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Parser Reflection API Library

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.

This library can be used for analysing the source code, automatic proxy creation and much more.
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.

[![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)
[![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)
Expand Down Expand Up @@ -31,6 +31,14 @@ Just use `Go\ParserReflection` package reflection classes like traditional ones:
$parsedClass = new \Go\ParserReflection\ReflectionClass(SomeClass::class);
var_dump($parsedClass->getMethods());
```
Or you can use an additional classes [`ReflectionFile`][0] and [`ReflectionFileNamespace`][1] to analyse a raw PHP files

```php
$parsedFile = new \Go\ParserReflection\ReflectionFile('SomeClass.php');
$fileNameSpaces = $parsedFile->getFileNamespaces()
var_dump($fileNameSpaces);
var_dump($fileNameSpaces[0]->getClass(SomeClass::class)->getMethods();
```

How it works?
------------
Expand All @@ -48,3 +56,6 @@ Compatibility
------------

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.

[0]: docs/reflection_file.md
[1]: docs/reflection_file_namespace.md
16 changes: 16 additions & 0 deletions docs/relection_class.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ReflectionClass
==============

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]

But be careful, that several methods require the class to be loaded into the memory, otherwise an exception will be thrown.

List of methods, that require class to be loaded
---------

- ReflectionClass::newInstance — Creates a new class instance from given arguments.
- ReflectionClass::newInstanceArgs — Creates a new class instance from given arguments.
- ReflectionClass::newInstanceWithoutConstructor — Creates a new class instance without invoking the constructor.
- ReflectionClass::setStaticPropertyValue — Sets static property value

[0]: http://php.net/manual/en/class.reflectionclass.php
44 changes: 44 additions & 0 deletions docs/relection_file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ReflectionFile
==============

The `ReflectionFile` class reports an information about a file with valid PHP source code. This class is not available in the standard PHP

API
---

```php
class ReflectionFile
{
public function __construct($fileName, $topLevelNodes = null) {}
public function getFileNamespace($namespaceName) {}
public function getFileNamespaces() {}
public function getName() {}
public function hasFileNamespace($namespaceName) {}
}
```

Methods
-------

- `ReflectionFile::__construct($fileName, $topLevelNodes = null)`

Constructs an instance of `ReflectionFile` object for given `fileName`. Can accept custom AST-tree nodes as optional parameter.

- `ReflectionFile::getFileNamespace($namespaceName)`

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.

- `ReflectionFile::getFileNamespaces()`

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.

- `ReflectionFile::getName()`

Returns a string with the name of file

- `ReflectionFile::hasFileNamespace($namespaceName)`

Checks if requested namespace is present in the file or not. Returns `true` if present.


[0]: reflection_file_namespace.md
99 changes: 99 additions & 0 deletions docs/relection_file_namespace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
ReflectionFileNamespace
==============

The `ReflectionFileNamespace` class reports an information about a namespace in the single file. This class is not available in the standard PHP

API
---

```php
class ReflectionFileNamespace
{
public function __construct($fileName, $namespaceName, Namespace_ $namespaceNode = null) {}
public function getClass($className) {}
public function getClasses() {}
public function getConstant($constantName) {}
public function getConstants() {}
public function getDocComment() {}
public function getEndLine() {}
public function getFileName() {}
public function getFunction($functionName) {}
public function getFunctions() {}
public function getName() {}
public function getNamespaceAliases() {}
public function getStartLine() {}
public function hasClass($className) {}
public function hasConstant($constantName) {}
public function hasFunction($functionName) {}
}
```

Methods
-------

- `ReflectionFileNamespace::__construct($fileName, $namespaceName, Namespace_ $namespaceNode = null)`

Constructs an instance of `ReflectionFileNamespace` object for given `fileName` and `namespaceName`. Can accept custom `Namespace_` node as optional parameter.

- `ReflectionFileNamespace::getClass($className)`

Returns the concrete [`ReflectionClass`][0] from the file namespace or `false` if there is no such a class in the current namespace

- `ReflectionFileNamespace::getClasses()`

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.

- `ReflectionFileNamespace::getConstant($constantName)`

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.

- `ReflectionFileNamespace::getConstants()`

Returns an array with all available constants in the namespace.

- `ReflectionFileNamespace::getDocComment()`

Returns a doc-block section for file namespace if present, otherwise `false`

- `ReflectionFileNamespace::getEndLine()`

Returns a end line for the namespace. Be careful, this value is not correct for simple `namespace Name;` definitions.

- `ReflectionFileNamespace::getFileName()`

Returns a string with the name of file

- `ReflectionFileNamespace::getFunction($functionName)`

Returns the concrete [`ReflectionFunction`][1] from the file namespace or `false` if there is no such a function in the current namespace

- `ReflectionFileNamespace::getFunctions()`

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.

- `ReflectionFile::getName()`

Returns a string with the name of current file namespace

- `ReflectionFileNamespace::getNamespaceAliases()`

Returns an array with all imported class namespaces and aliases for them in the current namespace.

- `ReflectionFileNamespace::getStartLine()`

Returns a start line for the namespace.

- `ReflectionFileNamespace::hasClass($className)`

Checks if the requested class is present in the file namespace or not. Returns `true` if present.

- `ReflectionFileNamespace::hasConstant($constantName)`

Checks if the requested constant is present in the file namespace or not. Returns `true` if present.

- `ReflectionFileNamespace::hasFunction($functionName)`

Checks if the requested function is present in the file namespace or not. Returns `true` if present.

[0]: reflection_class.md
[1]: reflection_function.md
15 changes: 15 additions & 0 deletions docs/relection_function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ReflectionFunction
==============

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]

But be careful, that several methods require the function to be loaded into the memory, otherwise an exception will be thrown.

List of methods, that require function to be loaded
---------

- ReflectionFunction::getClosure — Returns a dynamically created closure for the function
- ReflectionFunction::invoke — Invokes function
- ReflectionFunction::invokeArgs — Invokes function args

[0]: http://php.net/manual/en/class.reflectionfunction.php
16 changes: 16 additions & 0 deletions docs/relection_method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ReflectionMethod
==============

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]

But be careful, that several methods require the method and class to be loaded into the memory, otherwise an exception will be thrown.

List of methods, that require method and a corresponding class to be loaded
---------

- ReflectionMethod::getClosure — Returns a dynamically created closure for the method
- ReflectionMethod::invoke — Invokes method
- ReflectionMethod::invokeArgs — Invokes method args
- ReflectionMethod::setAccessible — Set method accessibility

[0]: http://php.net/manual/en/class.reflectionmethod.php
6 changes: 6 additions & 0 deletions docs/relection_parameter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ReflectionParameter
==============

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]

[0]: http://php.net/manual/en/class.reflectionparameter.php
15 changes: 15 additions & 0 deletions docs/relection_property.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ReflectionProperty
==============

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]

But be careful, that several methods require the property and class to be loaded into the memory, otherwise an exception will be thrown.

List of methods, that require property and a corresponding class to be loaded
---------

- ReflectionProperty::setAccessible — Set property accessibility
- ReflectionProperty::setValue — Set property value


[0]: http://php.net/manual/en/class.reflectionproperty.php
6 changes: 6 additions & 0 deletions docs/relection_type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ReflectionType
==============

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]

[0]: http://php.net/manual/en/class.reflectiontype.php

0 comments on commit a34f6df

Please sign in to comment.