You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Composer fails to generate the autoloader if "vendor/attributes.php" is in the autoloading but is not available yet. As a workaround, a stub file is created when the plugin is activated.
@@ -178,36 +180,10 @@ it to your `.gitignore` file.
178
180
179
181
180
182
181
-
## Frequently Asked Questions
182
-
183
-
**Do I need to generate an optimized autoloader?**
184
-
185
-
You don't need to generate an optimized autoloader for this to work. The plugin uses code similar
186
-
to Composer to find classes. Anything that works with Composer should work with the plugin.
187
-
188
-
**Can I use the plugin during development?**
189
-
190
-
Yes, you can use the plugin during development, but keep in mind the attributes file is only
191
-
generated after the autoloader is dumped. If you modify attributes you'll have to run
192
-
`composer dump` to refresh the attributes file.
193
-
194
-
As a workaround you could have watchers on the directories that contain classes with attributes to
195
-
run `XDEBUG_MODE=off composer dump` when you make changes. [PhpStorm offers file watchers][phpstorm-watchers]. You could also use [spatie/file-system-watcher][], it only requires PHP. If the plugin is too slow for your liking,
196
-
try running the command with `COMPOSER_ATTRIBUTE_COLLECTOR_USE_CACHE=yes`, it will enable caching
197
-
and speed up consecutive runs.
198
-
199
-
200
-
201
183
## Test drive with the Symfony Demo
202
184
203
185
You can try the plugin with a fresh installation of the [Symfony Demo Application](https://github.com/symfony/demo).
204
186
205
-
After you followed the instruction to install the demo, get into the project's directory and install the plugin. You'll be asked if you trust the plugin and wish to activate it. If you wish to continue, choose `y`.
### A simpler way to configure your Dependency Injection Container
298
-
299
-
composer-attribute-collector can help simplify DIC (Dependency Injection Container) configuration.
300
-
Long error-prone YAML can be completely replaced with attributes and a compiler pass to use them.
301
-
You can still support both YAML and attributes, the "attribute" compiler pass would just configure
302
-
the services and tag them automatically.
303
-
304
-
For example, the package [ICanBoogie/MessageBus][] offers [PHP 8 attributes as an alternative to YAML](https://github.com/ICanBoogie/MessageBus#using-php-8-attributes-instead-of-yaml).
public function __invoke(CreateMenu $message)// ...
375
-
}
376
-
377
-
// ...
378
-
379
-
use ICanBoogie\MessageBus\Attribute\Vote;
380
-
381
-
#[Vote(Permissions::IS_ADMIN)]
382
-
final class IsAdmin implements Voter
383
-
{
384
-
// ...
385
-
}
386
-
```
387
-
388
-
389
-
390
-
### Configure components from attributes
391
-
392
-
Using attributes simplifies configuration, placing definition closer to the code, where it's used. ICanBoogie's router can be configured automatically from attributes. The following example demonstrates how the `Route` attribute can be used at the class level to define a prefix for the route attributes such as `Get` that are used to tag actions. Action identifiers can be inferred from the controller class and the method names e.g. `skills:list`.
393
-
394
-
```php
395
-
<?php
396
-
397
-
// …
398
-
399
-
#[Route('/skills')]
400
-
final class SkillController extends ControllerAbstract
401
-
{
402
-
#[Post]
403
-
private function create(): void
404
-
{
405
-
// …
406
-
}
407
-
408
-
#[Get('.html')]
409
-
private function list(): void
410
-
{
411
-
// …
412
-
}
413
-
414
-
#[Get('/summonable.html')]
415
-
private function summonable(): void
416
-
{
417
-
// …
418
-
}
419
-
420
-
#[Get('/learnable.html')]
421
-
private function learnable(): void
422
-
{
423
-
// …
424
-
}
425
-
426
-
#[Get('/:slug.html')]
427
-
private function show(string $slug): void
428
-
{
429
-
// …
430
-
}
431
-
}
432
-
```
433
-
434
-
Because the `Get` and `Post` attributes extend `Route`, all action methods can be retrieved with the `filterTargetMethods()` method.
Now then, configuring the router looks as simple as this:
444
-
445
-
```php
446
-
<?php
447
-
448
-
use ICanBoogie\Binding\Routing\ConfigBuilder;
449
-
450
-
/* @var ConfigBuilder $config */
451
-
452
-
$config->from_attributes();
453
-
```
454
-
455
-
456
-
457
-
## Using Attributes
458
-
459
-
### Filtering target methods
255
+
## Frequently Asked Questions
460
256
461
-
`filterTargetMethods()` can filter target methods using a predicate. This can be helpful when a number of attributes extend another one, and you are interested in collecting any instance of that attribute. The `filerTargetClasses()` and `filterTargetProperties()` methods provide similar feature for classes and properties.
257
+
**Do I need to generate an optimized autoloader?**
462
258
463
-
Let's say we have a `Route` attribute extended by `Get`, `Post`, `Put`…
259
+
You don't need to generate an optimized autoloader for this to work. The plugin uses code similar
260
+
to Composer to find classes. Anything that works with Composer should work with the plugin.
464
261
465
-
```php
466
-
<?php
262
+
**Can I use the plugin during development?**
467
263
468
-
use olvlvl\ComposerAttributeCollector\Attributes;
264
+
Yes, you can use the plugin during development, but keep in mind the attributes file is only
265
+
generated after the autoloader is dumped. If you modify attributes you'll have to run
0 commit comments