Skip to content

Commit

Permalink
Update readme with new namespaces for custom annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
loonytoons committed Nov 4, 2021
1 parent 5d7215f commit 4c6b64e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,13 @@ class MailHandler {

}
```
or if you prefer to use attributes, set `$useAttribute` to `true` and do this.
or if you prefer to use attributes, set `$useAttribute` to `true` and do this. Note that unlike annotations, a use statement is required for the attribute.

```php
<?php namespace App\Handlers\Events;

use App\User;use Collective\Annotations\Events\Attributes\Attributes\Hears;
use App\User;
use Collective\Annotations\Events\Attributes\Attributes\Hears;

class MailHandler {

Expand Down Expand Up @@ -290,8 +291,6 @@ As well as defining middleware inline in the route definition tags (`@Get`, `@Po
}
```



Or on a whole controller, with the same only/exclude filter syntax that you can use elsewhere in laravel:

```php
Expand Down Expand Up @@ -460,15 +459,19 @@ This is the equivalent of calling `Route::model('users', 'App\Users')`.

<a name="custom-annotations"></a>
## Custom Annotations
_Please Note: the namespaces have been updated in version 8.1 in order to allow PHP 8 attribute support._

If you want to register your own annotations, create a namespace containing subclasses of `Collective\Annotations\Routing\Annotations\Annotations\Annotation` - let's say `App\Http\Annotations`.
If you want to register your own annotations, create a namespace containing subclasses of `Collective\Annotations\Routing\Meta` - let's say `App\Http\Annotations`.\
(_For version 8.0 and older, extend `Collective\Annotations\Routing\Annotations\Annotations\Annotation`_)

Then, in your annotations service provider, override the `addRoutingAnnotations( RouteScanner $scanner )` method, and register your routing annotations namespace:

```php
<?php namespace App\Providers;

use Collective\Annotations\Routing\Annotations\Scanner as RouteScanner;
use Collective\Annotations\Routing\Scanner as RouteScanner;
# For version 8.0 and older use this instead of the above:
# use Collective\Annotations\Routing\Annotations\Scanner as RouteScanner;

/* ... then, in the class definition ... */

Expand All @@ -483,7 +486,7 @@ use Collective\Annotations\Routing\Annotations\Scanner as RouteScanner;
}
```

Your annotation classes must must have the `@Annotation` class annotation (see the following example).
Your annotation classes must have the `@Annotation` class annotation (see the following example).

There is an equivalent method for event annotations: `addEventAnnotations( EventScanner $scanner )`.

Expand All @@ -496,7 +499,9 @@ In a namespace - in this example, `App\Annotations`:
```php
<?php namespace App\Http\Annotations;

use Collective\Annotations\Routing\Annotations\Annotations\Annotation;
use Collective\Annotations\Routing\Meta;
# For version 8.0 and older use this instead of the above:
# use Collective\Annotations\Routing\Annotations\Annotations\Annotation;
use Collective\Annotations\Routing\Annotations\MethodEndpoint;
use ReflectionMethod;

Expand Down

0 comments on commit 4c6b64e

Please sign in to comment.