AttributeServicesLoader.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Routing\Loader;
  11. use Symfony\Component\Config\Loader\Loader;
  12. use Symfony\Component\Routing\RouteCollection;
  13. /**
  14. * Loads routes from a list of tagged classes by delegating to the attribute class loader.
  15. *
  16. * @author Nicolas Grekas <p@tchwork.com>
  17. */
  18. final class AttributeServicesLoader extends Loader
  19. {
  20. /**
  21. * @param class-string[] $taggedClasses
  22. */
  23. public function __construct(
  24. private array $taggedClasses = [],
  25. ) {
  26. }
  27. public function load(mixed $resource, ?string $type = null): RouteCollection
  28. {
  29. $collection = new RouteCollection();
  30. foreach ($this->taggedClasses as $class) {
  31. $collection->addCollection($this->import($class, 'attribute'));
  32. }
  33. return $collection;
  34. }
  35. public function supports(mixed $resource, ?string $type = null): bool
  36. {
  37. return 'routing.controllers' === $resource;
  38. }
  39. }