public function mapValue(Reflection\Property $property, $value) { if ($property->hasOption(Reflection\Property::OPTION_ASSOC) && $property->getOption(Reflection\Property::OPTION_ASSOC) instanceof Association\ManyToOne && !empty($value)) { return $value[0]; } return $value; }
/** * Parse properties from annotations * * @param string $docComment * * @throws Exception\EntityException */ private function _parseProperties($docComment) { $properties = []; foreach (Reflection\Annotation::parseProperties($docComment) as $definition) { try { $property = new Reflection\Property($definition[2], $definition[3], $this, !$definition[1], $definition[4]); } catch (Exception\PropertyException $e) { throw new Exception\EntityException($e->getMessage(), $this->className, $definition[0]); } // Prevent duplications if (isset($properties[$property->getName()])) { throw new Exception\EntityException("Duplicate property with name '" . $property->getName() . "'!", $this->className, $definition[0]); } if (in_array($property->getName(), $this->publicProperties)) { throw new Exception\EntityException("Property '" . $property->getName() . "' already defined as public property!", $this->className, $definition[0]); } // Primary property if ($property->hasOption(Reflection\Property::OPTION_PRIMARY)) { if ($this->hasPrimary()) { throw new Exception\EntityException("Primary already defined!", $this->className, $definition[0]); } $this->primaryName = $property->getName(); } if ($property->hasOption(Reflection\Property::OPTION_ASSOC) && $this->primaryName === null) { throw new Exception\EntityException("You must define primary property before the association!", $this->className, $definition[0]); } $this->properties[$property->getName()] = $property; } }
public function unmapValue(Entity\Reflection\Property $property, $value) { // Call map filter from property option if ($property->hasOption(Entity\Reflection\Property::OPTION_MAP_FILTER)) { $value = call_user_func($property->getOption(Entity\Reflection\Property::OPTION_MAP_FILTER)[1], $value); } if ($value instanceof Entity\Collection) { return $this->unmapCollection($value); } elseif ($value instanceof Entity) { return $this->unmapEntity($value); } // Call adapter's mapping if needed if (!$property->getEntityReflection()->hasAdapter()) { throw new Exception\InvalidArgumentException("Entity " . $property->getEntityReflection()->getClassName() . " has no adapter defined!"); } if (isset($this->adapterMappings[$property->getEntityReflection()->getAdapterName()])) { return $this->adapterMappings[$property->getEntityReflection()->getAdapterName()]->unmapValue($property, $value); } return $value; }