LeanMapper\Entity::useMapper PHP Метод

useMapper() приватный Метод

Provides an mapper for entity
private useMapper ( leanmapper\IMapper $mapper )
$mapper leanmapper\IMapper
    private function useMapper(IMapper $mapper)
    {
        if ($this->mapper === null) {
            $newProperties = $this->getReflection($mapper)->getEntityProperties();
            foreach ($this->getCurrentReflection()->getEntityProperties() as $oldProperty) {
                $oldColumn = $oldProperty->getColumn();
                if ($oldColumn !== null) {
                    $name = $oldProperty->getName();
                    if (!isset($newProperties[$name]) or $newProperties[$name]->getColumn() === null) {
                        throw new InvalidStateException('Inconsistent sets of properties detected in entity ' . get_called_class() . '.');
                    }
                    if ($this->row->hasColumn($oldColumn)) {
                        $newColumn = $newProperties[$name]->getColumn();
                        $value = $this->row->{$oldColumn};
                        unset($this->row->{$oldColumn});
                        $this->row->{$newColumn} = $value;
                    }
                }
            }
            $this->mapper = $mapper;
            $this->row->setMapper($mapper);
            $this->currentReflection = null;
        } elseif ($this->mapper != $mapper) {
            // intentionally !=, we want to ensure that types and states are same
            throw new InvalidStateException("Given mapper isn't same as mapper already present in entity " . get_called_class() . '.');
        }
    }