Nextras\Orm\Mapper\Dbal\StorageReflection\StorageReflection::addMapping PHP Метод

addMapping() публичный Метод

Adds mapping.
public addMapping ( string $entity, string $storage, callable $toEntityCb = null, callable $toStorageCb = null ) : StorageReflection
$entity string
$storage string
$toEntityCb callable
$toStorageCb callable
Результат StorageReflection
    public function addMapping($entity, $storage, callable $toEntityCb = null, callable $toStorageCb = null)
    {
        if (isset($this->mappings[self::TO_ENTITY][$storage])) {
            throw new InvalidStateException("Mapping for {$storage} column is already defined.");
        } elseif (isset($this->mappings[self::TO_STORAGE][$entity])) {
            throw new InvalidStateException("Mapping for {$entity} property is already defined.");
        }
        $this->mappings[self::TO_ENTITY][$storage] = [$entity, $toEntityCb];
        $this->mappings[self::TO_STORAGE][$entity] = [$storage, $toStorageCb];
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * @param string   $propertyName
  * @param callable $toEntityTransform
  * @param callable $toSqlTransform
  * @throws InvalidPropertyException
  */
 public function addGenericArrayMapping($propertyName, callable $toEntityTransform, callable $toSqlTransform)
 {
     $this->validateProperty($propertyName);
     $this->storageReflection->addMapping($propertyName, $this->storageReflection->convertEntityToStorageKey($propertyName), function ($value) use($toEntityTransform) {
         return PgArray::parse($value, $toEntityTransform);
     }, function ($value) use($toSqlTransform) {
         return PgArray::serialize($value, $toSqlTransform);
     });
 }