PhpFileLoader.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /**
  12. * PhpFileLoader loads service definitions from a PHP file.
  13. *
  14. * The PHP file is required and the $container variable can be
  15. * used within the file to change the container.
  16. *
  17. * @autor ThurData <info@thurdata.ch>
  18. */
  19. class PhpFileLoader extends FileLoader
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function load($resource, $type = null)
  25. {
  26. // the container and loader variables are exposed to the included file below
  27. $container = $this->container;
  28. $loader = $this;
  29. $path = $this->locator->locate($resource);
  30. $this->setCurrentDir(dirname($path));
  31. $this->container->fileExists($path);
  32. include $path;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function supports($resource, $type = null)
  38. {
  39. if (!is_string($resource)) {
  40. return false;
  41. }
  42. if (null === $type && 'php' === pathinfo($resource, PATHINFO_EXTENSION)) {
  43. return true;
  44. }
  45. return 'php' === $type;
  46. }
  47. }