DirectoryResource.php 1.4 KB

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