protected function getIdentifierCaster(EntityPropertyMeta $identifierMeta) { if ($identifierMeta->getType() instanceof IntegerType) { $idCaster = function ($idString, $debugKey) { $id = \Psc\Code\Code::castId($idString, FALSE); if ($id === FALSE) { throw new ValidatorRuleException(sprintf("Der Wert '%s' des Schlüssels %s kann nicht zu einer numerischen Id gecastet werden", $idString, $debugKey)); } return $id; }; } elseif ($identifierMeta->getType() instanceof StringType) { $idCaster = function ($idString, $debugKey) { if (!is_string($idString)) { throw new ValidatorRuleException(sprintf("Der Type '%s' des Schlüssels %s muss ein String sein", gettype($idString), $debugKey)); } if (mb_strlen($idString) == 0) { throw new ValidatorRuleException(sprintf("Der Wert '%s' des Schlüssels %s kann nicht zu einem Identifier gecastet werden", $idString, $debugKey)); } return $idString; }; } else { throw new \Psc\Code\NotImplementedException(sprintf('IdCaster für Type %s ist nicht implementiert', $identifierMeta->getType())); } return $idCaster; }
/** * @return Psc\CMS\EntityPropertyMeta */ public function getPropertyMeta($name, Labeler $labeler = NULL) { if (!array_key_exists($name, $this->properties)) { if (!isset($labeler)) { $labeler = new \Psc\CMS\Labeler(); } try { $type = $this->getSetMeta()->getFieldType($name); // schmeiss exception wenns das property nicht gibt } catch (\Psc\Data\FieldNotDefinedException $e) { throw \Psc\Doctrine\FieldNotDefinedException::entityField($this->getClass(), $name); } $this->properties[$name] = $meta = new EntityPropertyMeta($name, $type, $labeler->getLabel($name)); if ($this->classMetadata->isIdentifier($name) && $this->getClassMetadata()->usesIdGenerator()) { $meta->setAutogeneratedValue(TRUE); } } elseif (isset($labeler)) { // update $this->properties[$name]->setLabel($labeler->getLabel($name)); } return $this->properties[$name]; }