infrastructure/Assetic/Factory/Resource/DirectoryResource.php line 52

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the Symfony framework.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace Symfony\Bundle\AsseticBundle\Factory\Resource;
  12. use Assetic\Factory\Resource\DirectoryResource as BaseDirectoryResource;
  13. use Symfony\Component\Templating\Loader\LoaderInterface;
  14. /**
  15. * A directory resource that creates Symfony2 templating resources.
  16. *
  17. * @author Kris Wallsmith <kris@symfony.com>
  18. */
  19. class DirectoryResource extends BaseDirectoryResource
  20. {
  21. protected \Symfony\Component\Templating\Loader\LoaderInterface $loader;
  22. protected $bundle;
  23. protected $path;
  24. /**
  25. * Constructor.
  26. *
  27. * @param LoaderInterface $loader The templating loader
  28. * @param string $bundle The current bundle name
  29. * @param string $path The directory path
  30. * @param string $pattern A regex pattern for file basenames
  31. */
  32. public function __construct(LoaderInterface $loader, $bundle, $path, $pattern = null)
  33. {
  34. $this->loader = $loader;
  35. $this->bundle = $bundle;
  36. $this->path = rtrim($path, '/').'/';
  37. parent::__construct($path, $pattern);
  38. }
  39. #[\Override]
  40. public function getIterator(): \Traversable
  41. {
  42. return is_dir($this->path)
  43. ? new DirectoryResourceIterator($this->loader, $this->bundle, $this->path, $this->getInnerIterator())
  44. : new \EmptyIterator();
  45. }
  46. }