ContainerAwareLoader.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\Bridge\Doctrine\DataFixtures;
  11. use Doctrine\Common\DataFixtures\FixtureInterface;
  12. use Doctrine\Common\DataFixtures\Loader;
  13. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  14. use Symfony\Component\DependencyInjection\ContainerInterface;
  15. /**
  16. * Doctrine data fixtures loader that injects the service container into
  17. * fixture objects that implement ContainerAwareInterface.
  18. *
  19. * Note: Use of this class requires the Doctrine data fixtures extension, which
  20. * is a suggested dependency for Symfony.
  21. */
  22. class ContainerAwareLoader extends Loader
  23. {
  24. private $container;
  25. public function __construct(ContainerInterface $container)
  26. {
  27. $this->container = $container;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function addFixture(FixtureInterface $fixture)
  33. {
  34. if ($fixture instanceof ContainerAwareInterface) {
  35. $fixture->setContainer($this->container);
  36. }
  37. parent::addFixture($fixture);
  38. }
  39. }