public static function createFor($entityClass, $collectionPropertyName, DCPackage $dc) { $entityMeta = $dc->getEntityMeta($entityClass); $property = $entityMeta->getPropertyMeta($collectionPropertyName); $collectionClass = $property->getRelationEntityClass(); return new static($entityMeta, $collectionPropertyName, $dc->getRepository($collectionClass->getFQN())); }
/** * Erstellt einen Synchronizer für das $collectionPropertyName in $entityClass * * @return PersistentCollectionSynchronizer */ public static function createFor($entityClass, $collectionPropertyName, DCPackage $dc) { $entityMeta = $dc->getEntityMeta($entityClass); $property = $entityMeta->getPropertyMeta($collectionPropertyName); $collectionClass = $property->getRelationEntityClass(); $synchronizer = new static($entityMeta, $property->getName(), new UniqueEntityHydrator($dc->getEntityManager()->getRepository($collectionClass->getFQN())), new EntityFactory($dc->getEntityMeta($collectionClass->getFQN()))); return $synchronizer; }
/** * * Achtung! nicht bool zurückgeben, stattdessen irgendeine Exception schmeissen * * Wird EmptyDataException bei validate() geworfen und ist der Validator mit optional aufgerufen worden, wird keine ValidatorException geworfen * * @return $data */ public function validate($data) { if ($data === NULL) { throw EmptyDataException::factory(NULL); } $repository = $this->dc->getRepository($this->entityMeta->getClass()); try { return $repository->hydrate($data); } catch (\Psc\Doctrine\EntityNotFoundException $e) { throw EmptyDataException::factory(NULL, $e); } }
/** * @return Psc\Doctrine\EntityRepository */ public function getRepository() { if (!isset($this->repository)) { $this->repository = $this->dc->getRepository($this->entityName); } return $this->repository; }
/** * * Wird EmptyDataException bei validate() geworfen und ist der Validator mit optional aufgerufen worden, wird keine ValidatorException geworfen * @return $data */ public function validate($data = NULL) { if ($data === NULL || $data === array()) { throw EmptyDataException::factory(new \Psc\Data\ArrayCollection()); } if (!is_array($data)) { throw new \InvalidArgumentException('Parameter ist als Array erwartet. ' . Code::varInfo($data) . ' wurde übergeben'); } $identifierCaster = $this->getIdentifierCaster($this->entityMeta->getIdentifier()); $repository = $this->dc->getRepository($this->entityMeta->getClass()); $entities = new ArrayCollection(); foreach ($data as $key => $identifierString) { $identifier = $identifierCaster($identifierString, $key); $entities->add($repository->hydrate($identifier)); } return $entities; }
/** * @param string $con * @chainable */ public function setConnectionName($con) { // damit das safer ist, updaten wir das doctrine package, wenn das hier gesetzt wird if (isset($this->dc) && $con != $this->con) { $this->dc->setEntityManager($this->dc->getModule()->getEntityManager($con)); } $this->con = $con; return $this; }
/** * Gibt die EntityMeta zu diesem (einem bestimmten) Entity zurück * * @param string|NULL $entityClass wird die klasse nicht übergeben wird $this->getEntityName() genommen * @return Psc\CMS\EntityMetaData */ public function getEntityMeta($entityClass = NULL) { return $this->dc->getEntityMeta($entityClass ?: $this->getEntityname()); }
/** * @return Psc\Doctrine\EntityRepository */ public function getRoleRepository($roleName) { return $this->dc->getRepository($this->getRoleFQN($roleName)); }
public function __construct($entityName, DCPackage $dc) { $this->em = $dc->getEntityManager(); $this->entityName = $dc->getModule()->getEntityName($entityName); }