diff --git a/README.md b/README.md index ca8147b..fad3400 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,10 @@ Where the FqsenResolver can resolve: In order to resolve a type you will have to instantiate the class `\phpDocumentor\Reflection\TypeResolver` and call its `resolve` method like this: - $typeResolver = new \phpDocumentor\Reflection\TypeResolver(); - $type = $typeResolver->resolve('string|integer'); +```php +$typeResolver = new \phpDocumentor\Reflection\TypeResolver(); +$type = $typeResolver->resolve('string|integer'); +``` In this example you will receive a Value Object of class `\phpDocumentor\Reflection\Types\Compound` that has two elements, one of type `\phpDocumentor\Reflection\Types\String_` and one of type @@ -77,8 +79,10 @@ in which namespace the given expression occurs and which namespace aliases (or i A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using the `\phpDocumentor\Reflection\FqsenResolver` class' `resolve` method, like this: - $fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver(); - $fqsen = $fqsenResolver->resolve('\phpDocumentor\Reflection\FqsenResolver::resolve()'); +```php +$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver(); +$fqsen = $fqsenResolver->resolve('\phpDocumentor\Reflection\FqsenResolver::resolve()'); +``` In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class name and element name) and receive a Value Object of type `\phpDocumentor\Reflection\Fqsen`. @@ -95,7 +99,6 @@ names. For example, you have this file: ```php - '\phpDocumentor\Reflection\Types'] - ); +```php +$context = new \phpDocumentor\Reflection\Types\Context( + '\My\Example', + [ 'Types' => '\phpDocumentor\Reflection\Types'] +); +``` Or by using the `\phpDocumentor\Reflection\Types\ContextFactory` to instantiate a new context based on a Reflector object or by providing the namespace that you'd like to extract and the source code of the file in which the given type expression occurs. - $contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory(); - $context = $contextFactory->createFromReflector(new ReflectionMethod('\My\Example\Classy', '__construct')); +```php +$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory(); +$context = $contextFactory->createFromReflector(new ReflectionMethod('\My\Example\Classy', '__construct')); +``` or - $contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory(); - $context = $contextFactory->createForNamespace('\My\Example', file_get_contents('My/Example/Classy.php')); +```php +$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory(); +$context = $contextFactory->createForNamespace('\My\Example', file_get_contents('My/Example/Classy.php')); +``` ### Using the Context @@ -145,8 +154,10 @@ class as second argument and the Resolvers will take this into account when reso To obtain the resolved class name for the `@var` tag in the example above you can do: - $typeResolver = new \phpDocumentor\Reflection\TypeResolver(); - $type = $typeResolver->resolve('Types\Context', $context); +```php +$typeResolver = new \phpDocumentor\Reflection\TypeResolver(); +$type = $typeResolver->resolve('Types\Context', $context); +``` When you do this you will receive an object of class `\phpDocumentor\Reflection\Types\Object_` for which you can call the `getFqsen` method to receive a Value Object that represents the complete FQSEN. So that would be @@ -161,8 +172,10 @@ the `getFqsen` method to receive a Value Object that represents the complete FQS Another example is on how to resolve the FQSEN of a method as can be seen with the `@see` tag in the example above. To resolve that you can do the following: - $fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver(); - $type = $fqsenResolver->resolve('Classy::otherFunction()', $context); +```php +$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver(); +$type = $fqsenResolver->resolve('Classy::otherFunction()', $context); +``` Because Classy is a Class in the current namespace its FQSEN will have the `My\Example` namespace and by calling the `resolve` method of the FQSEN Resolver you will receive an `Fqsen` object that refers to