PhpFileLoader.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 form the file to change the container.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class PhpFileLoader extends FileLoader
  21. {
  22. /**
  23. * Loads a PHP file.
  24. *
  25. * @param mixed $file The resource
  26. * @param string $type The resource type
  27. */
  28. public function load($file, $type = null)
  29. {
  30. // the container and loader variables are exposed to the included file below
  31. $container = $this->container;
  32. $loader = $this;
  33. $path = $this->locator->locate($file);
  34. $this->setCurrentDir(dirname($path));
  35. $this->container->addResource(new FileResource($path));
  36. include $path;
  37. }
  38. /**
  39. * Returns true if this class supports the given resource.
  40. *
  41. * @param mixed $resource A resource
  42. * @param string $type The resource type
  43. *
  44. * @return Boolean true if this class supports the given resource, false otherwise
  45. */
  46. public function supports($resource, $type = null)
  47. {
  48. return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION);
  49. }
  50. }