Drupal investigation

PhpFileLoader.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }