AbstractFixture.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Doctrine\Common\DataFixtures;
  3. use Doctrine\Common\DataFixtures\ReferenceRepository;
  4. /**
  5. * Abstract Fixture class helps to manage references
  6. * between fixture classes in order to set relations
  7. * among other fixtures
  8. *
  9. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  10. */
  11. abstract class AbstractFixture implements SharedFixtureInterface
  12. {
  13. /**
  14. * Fixture reference repository
  15. *
  16. * @var ReferenceRepository
  17. */
  18. protected $referenceRepository;
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function setReferenceRepository(ReferenceRepository $referenceRepository)
  23. {
  24. $this->referenceRepository = $referenceRepository;
  25. }
  26. /**
  27. * Set the reference entry identified by $name
  28. * and referenced to managed $object. If $name
  29. * already is set, it overrides it
  30. *
  31. * @param string $name
  32. * @param object $object - managed object
  33. * @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference
  34. * @return void
  35. */
  36. public function setReference($name, $object)
  37. {
  38. $this->referenceRepository->setReference($name, $object);
  39. }
  40. /**
  41. * Set the reference entry identified by $name
  42. * and referenced to managed $object. If $name
  43. * already is set, it throws a
  44. * BadMethodCallException exception
  45. *
  46. * @param string $name
  47. * @param object $object - managed object
  48. * @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference
  49. * @throws \BadMethodCallException - if repository already has
  50. * a reference by $name
  51. * @return void
  52. */
  53. public function addReference($name, $object)
  54. {
  55. $this->referenceRepository->addReference($name, $object);
  56. }
  57. /**
  58. * Loads an object using stored reference
  59. * named by $name
  60. *
  61. * @param string $name
  62. * @see Doctrine\Common\DataFixtures\ReferenceRepository::getReference
  63. * @return object
  64. */
  65. public function getReference($name)
  66. {
  67. return $this->referenceRepository->getReference($name);
  68. }
  69. /**
  70. * Check if an object is stored using reference
  71. * named by $name
  72. *
  73. * @param string $name
  74. * @see Doctrine\Common\DataFixtures\ReferenceRepository::hasReference
  75. * @return boolean
  76. */
  77. public function hasReference($name)
  78. {
  79. return $this->referenceRepository->hasReference($name);
  80. }
  81. }