PhpFileLoader.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\DependencyInjection\Loader;
  11. use Symfony\Component\Config\Resource\FileResource;
  12. /**
  13. * PhpFileLoader loads service definitions from a PHP file.
  14. *
  15. * The PHP file is required and the $container variable can be
  16. * used within the file to change the container.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class PhpFileLoader extends FileLoader
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function load($resource, $type = null)
  26. {
  27. // the container and loader variables are exposed to the included file below
  28. $container = $this->container;
  29. $loader = $this;
  30. $path = $this->locator->locate($resource);
  31. $this->setCurrentDir(\dirname($path));
  32. $this->container->addResource(new FileResource($path));
  33. include $path;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function supports($resource, $type = null)
  39. {
  40. return \is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION);
  41. }
  42. }