コード例 #1
0
 /**
  * @param string $name
  *
  * @return object
  */
 protected function getFixture($name)
 {
     $manager = $this->getKernel()->getContainer()->get('doctrine.orm.default_entity_manager');
     if (!$this->referenceRepository->hasReference($name)) {
         if (isset(static::$referenceRepositoryData[$name])) {
             $reference = $manager->getReference(static::$referenceRepositoryData[$name]['class'], static::$referenceRepositoryData[$name]['identifier']);
             $this->referenceRepository->setReference($name, $reference);
         }
     }
     return $this->referenceRepository->getReference($name);
 }
コード例 #2
0
 /**
  * @param string $referenceName
  * @param bool $persist
  * @param callable $objectLoader
  * @return mixed
  */
 protected function load($referenceName, $persist, \Closure $objectLoader, $defaultReferenceName = '')
 {
     if (is_null($referenceName)) {
         $referenceName = $defaultReferenceName;
     }
     if ($this->referenceRepository->hasReference($referenceName)) {
         return $this->referenceRepository->getReference($referenceName);
     }
     $object = $objectLoader($this, $referenceName);
     if ($persist) {
         $this->objectManager->persist($object);
     }
     $this->referenceRepository->setReference($referenceName, $object);
     return $object;
 }
コード例 #3
0
 /**
  * Returns an object from the manager
  *
  * @param string $class
  * @param string $code
  *
  * @throws \Exception
  *
  * @return object
  */
 protected function findObject($class, $code)
 {
     $reference = $class . '.' . $code;
     if ($this->referenceRepository && $this->referenceRepository->hasReference($reference)) {
         return $this->referenceRepository->getReference($reference);
     } else {
         $repository = $this->doctrine->getManagerForClass($class)->getRepository($class);
         if (!$repository instanceof IdentifiableObjectRepositoryInterface) {
             throw new \Exception(sprintf('Repository "%s" of class "%s" does not implement ' . '"Akeneo\\Component\\StorageUtils\\Repository\\IdentifiableObjectRepositoryInterface".', get_class($repository), $class));
         }
         return $repository->findOneByIdentifier($code);
     }
 }
コード例 #4
0
 /**
  * Returns an object from the manager
  *
  * @param string $class
  * @param string $code
  *
  * @return object
  */
 protected function findObject($class, $code)
 {
     $reference = $class . '.' . $code;
     if ($this->referenceRepository && $this->referenceRepository->hasReference($reference)) {
         return $this->referenceRepository->getReference($reference);
     } else {
         $repository = $this->doctrine->getManagerForClass($class)->getRepository($class);
         if (!$repository instanceof ReferableEntityRepositoryInterface) {
             throw new \Exception(sprintf('Repository "%s" of class "%s" is not referable', get_class($repository), $class));
         }
         return $repository->findByReference($code);
     }
 }
コード例 #5
0
 /**
  * Check if an object is stored using reference
  * named by $name
  * 
  * @param string $name
  * @see Doctrine\Common\DataFixtures\ReferenceRepository::hasReference
  * @return boolean
  */
 public function hasReference($name)
 {
     return $this->referenceRepository->hasReference($name);
 }