getProperty() public method

public getProperty ( string $name ) : PropertyMetadata
$name string
return PropertyMetadata
Exemplo n.º 1
0
 public function parseMetadata($class, &$fileDependencies)
 {
     $this->reflection = new ClassType($class);
     $this->metadata = new EntityMetadata($class);
     $this->primaryKey = [];
     $this->loadProperties($fileDependencies);
     $this->loadGettersSetters();
     // makes id property virtual on entities with composite primary key
     if ($this->primaryKey && $this->metadata->hasProperty('id')) {
         $this->metadata->getProperty('id')->isVirtual = TRUE;
     }
     $fileDependencies = array_unique($fileDependencies);
     $this->metadata->setPrimaryKey($this->primaryKey ?: ['id']);
     return $this->metadata;
 }
Exemplo n.º 2
0
 /**
  * @param string $propertyName
  * @throws InvalidPropertyException
  */
 public function validateProperty($propertyName)
 {
     try {
         $this->entityMetadata->getProperty($propertyName);
     } catch (InvalidArgumentException $e) {
         throw InvalidPropertyException::createNonexistentProperty($propertyName, $e);
     }
 }
Exemplo n.º 3
0
 public function getForeignKey($name)
 {
     $metadata = $this->metadata->getProperty($name);
     if (!in_array($metadata->relationshipType, [PropertyMetadata::RELATIONSHIP_MANY_HAS_ONE, PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE, PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE_DIRECTED], TRUE)) {
         throw new InvalidArgumentException("There is no HAS ONE relationship in '{$name}' property.");
     }
     if (isset($this->validated[$name])) {
         return $this->data[$name]->getPrimaryValue();
     }
     $this->initDefaultValue($metadata);
     return $this->data[$name];
 }
Exemplo n.º 4
0
 protected function initPrimaryKey()
 {
     $primaryKey = array_values(array_filter(array_map(function (PropertyMetadata $metadata) {
         return $metadata->isPrimary && !$metadata->isVirtual ? $metadata->name : null;
     }, $this->metadata->getProperties())));
     if (empty($primaryKey)) {
         throw new InvalidStateException("Entity {$this->reflection->name} does not have defined any primary key.");
     } elseif (!$this->metadata->hasProperty('id') || !$this->metadata->getProperty('id')->isPrimary) {
         throw new InvalidStateException("Entity {$this->reflection->name} has to have defined \$id property as {primary} or {primary-proxy}.");
     }
     $this->metadata->setPrimaryKey($primaryKey);
 }
Exemplo n.º 5
0
 protected function parseFilteredRelationship(PropertyMetadata $property, $args)
 {
     $sourceName = ltrim($args[0], '$');
     $sourceProperty = $this->metadata->getProperty($sourceName);
     if ($sourceProperty->relationshipType === PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE || $sourceProperty->relationshipType === PropertyMetadata::RELATIONSHIP_MANY_HAS_ONE) {
         $property->container = 'Nextras\\Orm\\Entity\\PropertyContainers\\FilteredRelationshipContainerContainer';
     } else {
         $property->container = 'Nextras\\Orm\\Entity\\PropertyContainers\\FilteredRelationshipCollectionContainer';
     }
     $property->args = [$sourceName];
     unset($this->storageProperties[$property->name]);
 }
Exemplo n.º 6
0
 public function setValues($values, $erase = FALSE) : self
 {
     $this->initEntityRelations();
     foreach ($values as $property => $value) {
         if ($this[$property] instanceof Nette\Forms\IControl) {
             $value = $value === '' ? NULL : $value;
             if ($this[$property] instanceof Nette\Forms\Controls\Checkbox && !$value && $this->metadata->getProperty($property)->isNullable) {
                 $value = NULL;
             }
             $this->entity->setValue($property, $value);
         }
     }
     return parent::setValues($values, $erase);
 }
Exemplo n.º 7
0
 public function getRawProperty($name)
 {
     $this->metadata->getProperty($name);
     return isset($this->data[$name]) ? $this->data[$name] : null;
 }
Exemplo n.º 8
0
 public function getter($element, $chain, EntityMetadata $sourceEntityMeta)
 {
     $column = array_shift($chain);
     $propertyMeta = $sourceEntityMeta->getProperty($column);
     // check if property exists
     $value = $element->hasValue($column) ? $element->getValue($column) : null;
     if ($value instanceof IRelationshipCollection) {
         throw new InvalidStateException('You can not sort by hasMany relationship.');
     }
     if (!$chain) {
         return $this->normalizeValue($value, $propertyMeta);
     } else {
         $targetEntityMeta = $this->metadataStorage->get($propertyMeta->relationship->entity);
         return $this->getter($value, $chain, $targetEntityMeta);
     }
 }