Skip to content

Commit 8a60ed9

Browse files
authored
Update docs
1 parent 9e604e6 commit 8a60ed9

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

README.md

+24-22
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,48 @@ Usage
2929

3030
### Initialization
3131

32-
Prior to first use library can be optionally initialized.
33-
34-
Following example uses the Composer autoloader from the project, where library is used, as a dependency:
35-
36-
```php
37-
$locator = new \Go\ParserReflection\Locator\ComposerLocator();
38-
\Go\ParserReflection\ReflectionEngine::init($locator);
39-
```
40-
41-
Following example uses Composer's autoloader located at a given path:
42-
43-
```php
44-
$composerLoader = require_once '/path/to/vendor/autoload.php';
45-
$composerLoader->unregister();
46-
47-
$locator = new \Go\ParserReflection\Locator\ComposerLocator($composerLoader);
48-
\Go\ParserReflection\ReflectionEngine::init($locator);
49-
```
32+
Prior to the first use library can be optionally initialized. If you use Composer for installing packages and loading classes,
33+
then you shouldn't worry about initialization, library will be initialized automatically.
5034

5135
If project uses a custom autoloader then you should follow the next steps:
5236

53-
1. Create a class, that implements `\Go\ParserReflection\LocatorInterface`
37+
1. Create a new class that implements `\Go\ParserReflection\LocatorInterface`
5438
2. Create an instance of that class and pass it to the `ReflectionEngine::init()` method for initial configuration
5539

56-
### Actual Usage
40+
### Reflecting concrete classes/methods/properties without loading them
5741

5842
Just use `Go\ParserReflection` package reflection classes like traditional ones:
5943

6044
```php
6145
$parsedClass = new \Go\ParserReflection\ReflectionClass(SomeClass::class);
6246
var_dump($parsedClass->getMethods());
47+
48+
$parsedMethod = new \Go\ParserReflection\ReflectionMethod(SomeClass::class, 'someMethod');
49+
echo (string)$parsedMethod;
6350
```
6451

6552
Or you can use an additional classes [`ReflectionFile`][0] and [`ReflectionFileNamespace`][1] to analyse a raw PHP files:
6653

6754
```php
6855
$parsedFile = new \Go\ParserReflection\ReflectionFile('SomeClass.php');
6956
$fileNameSpaces = $parsedFile->getFileNamespaces();
70-
var_dump($fileNameSpaces);
71-
var_dump($fileNameSpaces[0]->getClass(SomeClass::class)->getMethods());
57+
// We can iterate over namespaces in the file
58+
foreach ($fileNameSpaces as $namespace) {
59+
$classes = $namespace->getClasses();
60+
// Iterate over the classes in the namespace
61+
foreach ($classes as $class) {
62+
echo "Found class: ", $class->getName(), PHP_EOL;
63+
// Now let's show all methods in the class
64+
foreach ($class->getMethods() as $method) {
65+
echo "Found class method: ", $class->getName(), '::', $method->getName(), PHP_EOL;
66+
}
67+
68+
// ...all properties in the class
69+
foreach ($class->getProperties() as $property) {
70+
echo "Found class property: ", $class->getName(), '->', $property->getName(), PHP_EOL;
71+
}
72+
}
73+
}
7274
```
7375

7476
How it works?

0 commit comments

Comments
 (0)