/** * @param string $v * @return bool */ public function isValid($v) { if ($v == $this->currentValue) { return true; } $entity = $this->em->findEntityBy($this->entityType, array($this->fieldName => $v)); if ($entity) { $this->addError($this->_("'%s' was already used. Please enter a different value.", $v)); return false; } return true; }
/** * @return \Hynage\ORM\EntityManager */ public function bootstrap() { $connection = new Connection($this->config->get('uri')); $dbPersister = new DatabasePersistence($connection); $em = new EntityManager(); $em->addPersister('database', $dbPersister); if ($this->config->has('entityNameFormatter')) { $em->setEntityNameFormatter($this->config->get('entityNameFormatter')); } if ($this->config->has('repositoryNameFormatter')) { $em->setRepositoryNameFormatter($this->config->get('repositoryNameFormatter')); } $this->em = $em; return $em; }
/** * @return \Hynage\ORM\EntityCollection|\Hynage\ORM\Entity */ public function load() { if ($this->data) { return $this->data; } $constraints = array($this->foreignFieldName => $this->entity->getValue($this->localFieldName)); $type = $this->type; switch ($type) { case self::TYPE_ENTITY: $this->data = $this->em->findEntityBy($this->className, $constraints); break; case self::TYPE_COLLECTION: $this->data = $this->em->findEntitiesBy($this->className, $constraints); break; default: throw new \InvalidArgumentException("Invalid proxy type '{$type}'."); } return $this->data; }