FileLocator.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\HttpKernel\Config;
  11. use Symfony\Component\Config\FileLocator as BaseFileLocator;
  12. use Symfony\Component\HttpKernel\KernelInterface;
  13. /**
  14. * FileLocator uses the KernelInterface to locate resources in bundles.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class FileLocator extends BaseFileLocator
  19. {
  20. private $kernel;
  21. private $path;
  22. /**
  23. * Constructor.
  24. *
  25. * @param KernelInterface $kernel A KernelInterface instance
  26. * @param null|string $path The path the global resource directory
  27. * @param array $paths An array of paths where to look for resources
  28. */
  29. public function __construct(KernelInterface $kernel, $path = null, array $paths = array())
  30. {
  31. $this->kernel = $kernel;
  32. if (null !== $path) {
  33. $this->path = $path;
  34. $paths[] = $path;
  35. }
  36. parent::__construct($paths);
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function locate($file, $currentPath = null, $first = true)
  42. {
  43. if ('@' === $file[0]) {
  44. return $this->kernel->locateResource($file, $this->path, $first);
  45. }
  46. return parent::locate($file, $currentPath, $first);
  47. }
  48. }