protected function initValidatorRule() { if (!isset($this->validatorRule)) { // wir lassen zu, dass die rule in sonderfällen von außen gesetzt wird $this->validatorRule = new SelectComboBoxValidatorRule($this->entityMeta->getClass(), $this->dc); } }
/** * * 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); } }
/** * Initialisiert den Synchronizer mit dem $entity in dem $this->collectionName vorhanden ist * * dies er gibt dann die fromCollection */ public function init(Entity $entity) { // check entity if ($entity->getEntityName() !== ($class = $this->entityMeta->getClass())) { throw new \InvalidArgumentException('Das übergebene Entity für diesen Synchronizer kann nur vom Typ: ' . $class . ' sein. Ein Entity des Typs ' . $entity->getEntityName() . ' wurde übergeben'); } // check relation $collectionMeta = $this->getCollectionPropertyMeta(); if (!$collectionMeta->isRelation()) { throw new \InvalidArgumentException(sprintf('Das Property %s von %s ist keine Collection. Das Property muss ManyToMany oder OneToMany sein', $this->collectionName, $this->entityMeta->getClass())); } }
/** * * 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; }
/** * Setzt das Element welches in der ComboBox ausgewählt ist * */ public function setSelected($item) { if (!isset($this->entityMeta)) { throw new \Psc\Exception('EntityMeta muss übergeben werden wenn selected gesetzt wird'); } $ec = $this->entityMeta->getClass(); if (!$item instanceof $ec) { throw new \InvalidArgumentException('Parameter Item für setSelected() muss vom Typ: ' . $ec . ' sein. ' . Code::varInfo($item) . ' wurde übergeben'); } $this->selected = $item; return $this; }
protected function initValidatorRule() { $this->validatorRule = new SelectComboBoxValidatorRule($this->entityMeta->getClass(), $this->dc); }