实体属性对应的值

@param object $entity  实体对象
@param string $proName 属性名称

@return mixed
@throws \InvalidArgumentException
179895
private static function getEntityProValue($entity, string $proName)
    {
        $tmpNodes     = \explode('_', $proName);
        $tmpNodes     = \array_map(function ($word) {
            return \ucfirst($word);
        }, $tmpNodes);
        $proName      = \implode('', $tmpNodes);
        $getterMethod = 'get' . $proName;

        if (!\method_exists($entity, $getterMethod)) {
            throw new \InvalidArgumentException('Entity object property getter method does not exist, properName=' . $proName);
        }

        return $entity->$getterMethod();
    }
687673
public function generateProxyClass($entity, $config)
    {
        if (!is_array($config) && !$config instanceof \ArrayAccess) {
            throw new Exception\InvalidArgumentException(
                'Invalid proxy class configuration; array or instance of ArrayAccess expected');
        }
        
        if (!is_object($entity)) {
            if ((is_string($entity) && (!class_exists($entity))) // non-existent class
                    || (!is_string($entity)) // not an object or string
            ) {
                throw new Exception\InvalidArgumentException(sprintf(
                        '%s expects an object or valid class name; received "%s"',
                        __METHOD__,
                        var_export($entity, 1)
                ));
            }
        }
        
        $this->serviceConfig = $config;
        
        $reflection  = new ReflectionClass($entity);
        $className = $reflection->getName();
        
        $class = ClassGenerator::fromArray([
            'name' => $this->getProxyClassName($className),
            'namespace_name' => $this->getProxyNamespace($className),
            'extended_class' => '\\' . $className,
            'implemented_interfaces' => array('\Zend\EventManager\EventManagerAwareInterface'),
            'methods' => $this->generateMethods($reflection),
            'properties' => [
                new PropertyGenerator('__wrappedObject', null, PropertyGenerator::FLAG_PUBLIC),
                new PropertyGenerator('__eventManager', null, PropertyGenerator::FLAG_PRIVATE),
                new PropertyGenerator('__commandStack', null, PropertyGenerator::FLAG_PRIVATE)
            ]
        ]);
        
        $source = "<?php\n" . $class->generate();
        
        $fileName        = $this->getProxyFileName($className);
        $parentDirectory = $this->proxyDirectory;
        
        if ( ! is_dir($parentDirectory) && (false === @mkdir($parentDirectory, 0775, true))) {
            throw new Exception\RuntimeException('Proxy directory '.$parentDirectory.' not found');
        }
        
        if ( ! is_writable($parentDirectory)) {
            throw new Exception\RuntimeException('Proxy directory '.$parentDirectory.' is not writable');
        }
        
        $tmpFileName = $fileName . '.' . uniqid('', true);
        file_put_contents($tmpFileName, $source);
        rename($tmpFileName, $fileName);
    }
728846
public function create(Entity $entity)
    {
        $result = $this->events->shouldExecute($entity, 'before', 'create');
        if (!$result) {
            return false;
        }
        $result = $this->doCreate($entity);
        $this->events->shouldExecute($entity, 'after', 'create');
        return $result;
    }
351779
public static function get($entity, $primaryValue)
    {
        $query = new Query($entity);
        $column = self::getInstance()->getEntityStructure($entity)->primaryColumn;
        $query->where($column->name, $primaryValue);
        return $query->one();
    }
1254665
public function getRightRecord(Entity $rightEntity, $foreignKey, $primaryValue)
    {
        if (!$primaryValue) {
            return null;
        }

        if ($this->inheritRightRepository) {
            $rightEntity->setRepository($this->getLeftEntity()->getRepository());
        }
        $entity = $rightEntity->where($foreignKey, $primaryValue);

        /**
         * Add conditions applied on query.
         */
        foreach ($this->getQuery()->getWhere()->getChildren() as $condition) {
            $entity->where(
                function(Parenthesis $parenthesis) use ($condition) {
                    $parenthesis->push($condition);
                }
            );
        }

        foreach ($this->getQuery()->getBinds('where') as $bind) {
            $entity->getQuery()->bind($bind, 'where');
        }
        
        return (new GetRecords($rightEntity))->executeOne();
    }
536796
public function getLevel($entity)
    {
        $primaryKey = $this->_getPrimaryKey();
        $id = $entity;
        if ($entity instanceof EntityInterface) {
            $id = $entity->get($primaryKey);
        }
        $config = $this->getConfig();
        $entity = $this->_table->find('all')
            ->select([$config['left'], $config['right']])
            ->where([$primaryKey => $id])
            ->first();

        if ($entity === null) {
            return false;
        }

        $query = $this->_table->find('all')->where([
            $config['left'] . ' <' => $entity[$config['left']],
            $config['right'] . ' >' => $entity[$config['right']],
        ]);

        return $this->_scope($query)->count();
    }
147380
public function one(Entity $entity)
    {
        $data = $entity->getCustomRepositoryCollection();
        $query = $entity->getQuery();

        return $data->first(function(Record $record) use ($query) {
            $where = $query->getWhere();
            if (!$where) {
                return true;
            }

            $children = $where->getChildren();
            $binds = $query->getBinds('where');

            foreach ($children as $i => $child) {
                if (!is_string($child)) {
                    continue;
                }

                if (preg_match('/^`[a-z]*` = \?$/', $child, $matches)) {
                    $field = substr($child, 1, strpos($child, '`', 1) - 1);
                    $value = $binds[$i];
                    
                    return $record->{$field} == $value;
                } else {
                    return false;
                }
            }

            return true;
        });
    }
234225
public function getPositionFieldByEntity($entity)
    {
        if (is_object($entity)) {
            $entity = ClassUtils::getClass($entity);
        }

        if (isset($this->positionField['entities'][$entity])) {
            return $this->positionField['entities'][$entity];

        } else {
            return $this->positionField['default'];
        }
    }
1192985
public function update($entity)
    {
        if ($this->idProperty === null) {
            throw new ConfigurationException('No idProperty set');
        }

        $id = $this->idProperty->getValue($entity);

        if ($id === null) {
            throw new ConfigurationException('Value of ' . $this->idProperty->getName() . ' is null');
        }

        $values = $this->getInsertValues($entity, $this->namingContention);
        $keyString = implode(array_keys($values), ' = ?,') . ' = ?';
        $idColumn = $this->namingContention->propertyToColumnName($this->idProperty);
        $onlyValues = array_values($values);
        $onlyValues[] = $id;

        $sql = "UPDATE $this->tableName SET $keyString WHERE $idColumn = ?";
        $sth = $this->pdo->prepare($sql);
        $sth->execute($onlyValues);
        return $id;
    }
133249
public function referencedBy( $entity )
    {

        if( !( $entity instanceof Base || $entity instanceof Container ) ) {
            throw new \InvalidArgumentException("You can only lookup references by Entity or Container");
        }

        $class = $entity instanceof Container
            ? $entity->class
            : $entity;

        $properties = $this->propertiesOfTypeGet( $class );

        // found a entity?
        if( !$properties ) {
            throw new \LogicException(
                sprintf(
                    "Can't find which entity property for repository `%s` references entity of type `%s`",
                    $this->entity,
                    $entityClass
                )
            );
        } elseif( count( $properties ) > 1 ) {
            throw new \LogicException(
                sprintf(
                    "Multiple columns [%s] reference a entity of this type [%s]. This is ambiguous. Can't help you here.",
                    implode( ",", $properties ),
                    \Bond\get_unqualified_class( $entity )
                )
            );
        }

        $property = array_pop( $properties );

        // get references to this entity
        $filterComponent = $this->getFindFilterFactory()
            ->get( $property, null, $entity );

        return $this->findByFilterComponents(
            FindFilterComponentFactory::FIND_ALL,
            array( $property => $filterComponent )
        );

    }
327373
public final function save(Entity $entity): ?int
    {
        $data = $entity->toArray();
        if (empty($data)) {
            throw new InvalidValueException('There is no data enough on entity for save action!');
        }

        // use only owned fields
        $data = array_intersect_key($data, array_flip(self::$tableInfo['@fields']));

        $return = null;

        // insert action
        if (!$entity->hasPrimaryValue()) {
            $return = $this->db->getLink()->getAgent()->insert($this->table, $data);
            // set primary value
            $entity->setPrimaryValue($return);
        } else {
            // update action
            $return = $this->db->getLink()->getAgent()->update($this->table, $data,
                "{$this->tablePrimary} = ?", [$entity->getPrimaryValue()]);
        }

        if (method_exists($this, 'onSave')) {
            $this->onSave($return);
        }

        return $return;
    }
1208255
private function getClassMetadata($entityName, EntityManagerInterface $entityManager)
    {
        try {
            return $entityManager->getClassMetadata($entityName);
        } catch (MappingException $e) {
        }

        $matches = array_filter(
            $this->getMappedEntities($entityManager),
            static function ($mappedEntity) use ($entityName) {
                return preg_match('{' . preg_quote($entityName) . '}', $mappedEntity);
            }
        );

        if (! $matches) {
            throw new InvalidArgumentException(sprintf(
                'Could not find any mapped Entity classes matching "%s"',
                $entityName
            ));
        }

        if (count($matches) > 1) {
            throw new InvalidArgumentException(sprintf(
                'Entity name "%s" is ambiguous, possible matches: "%s"',
                $entityName,
                implode(', ', $matches)
            ));
        }

        return $entityManager->getClassMetadata(current($matches));
    }
188923
public function getAdminType($entity)
    {
        if (null !== $this->type) {
            return $this->type;
        }

        if (method_exists($entity, 'getAdminType')) {
            return $entity->getAdminType();
        }

        throw new InvalidArgumentException(
            'You need to implement the getAdminType method in '.
            get_class($this).' or '.get_class($entity)
        );
    }
347708
public function generateBody(Entity $entity, FieldDescriptorProto $field)
    {
        $name      = $field->getName();
        $tag       = $field->getNumber();
        $extEntity = $this->getEntity($field->getExtendee());
        $extendee  = $extEntity->getNamespacedName();

        $nameQuoted     = var_export($name, true);
        $extendeeQuoted = var_export($extendee, true);

        $sizeCallback  = $this->generateSizeCallback($entity, $field);
        $readCallback  = $this->generateReadCallback($entity, $field);
        $writeCallback = $this->generateWriteCallback($entity, $field);
        $callbacks     = array_merge($readCallback, [null], $writeCallback, [null], $sizeCallback);
        $arguments     = [
            $extendeeQuoted,
            $nameQuoted,
            $tag,
            '$readCallback',
            '$writeCallback',
            '$sizeCallback',
            '__METHOD__'
        ];

        $body[] = 'if (self::$' . $name . ' !== null) {';
        $body[] = '    return self::$' . $name . ';';
        $body[] = '}';
        $body[] = null;
        $body   = array_merge($body, $callbacks);
        $body[] = null;
        $body[] = 'return self::$' . $name . ' = new \Protobuf\Extension\ExtensionField(' . implode(', ', $arguments) . ');';

        return $body;
    }
80978
public function load(EntityInterface $entity)
    {
        $adapter = $this->getAdapter();

        $relTable = $this->getParentTableName();
        $relPmk = $this->getParentPrimaryKey();

        $table = $this->getEntityDescriptor()->getTableName();
        $pmk = $this->getEntityDescriptor()->getPrimaryKey();
        $fnk = $this->getForeignKey();

        $onClause = "{$relTable}.{$relPmk} = {$table}.{$fnk}";

        $data = Sql::createSql($adapter)
            ->select($relTable)
            ->join($table, $onClause, null)
            ->where([
                "{$table}.{$pmk->getField()} = :id" => [
                    ':id' => $entity->{$pmk->getName()}
                ]
            ])
            ->first();

        $relEntity = $this->getParentEntityMapper()->createFrom($data);

        return null == $relEntity ? null :$this->registerEntity($relEntity);
    }
125544
public function validates($entity, $options = [])
    {
        $fieldname = $this->name();

        if (!isset($entity->{$fieldname})) {
            return true;
        }
        return $entity->{$fieldname}->validates($options);
    }
1290814
protected function _extractForeignKey($entity)
    {
        $foreignKey = (array)$this->_config['foreignKey'];
        $primaryKey = (array)$this->_table->getPrimaryKey();
        $pkValue = $entity->extract($primaryKey);

        return array_combine($foreignKey, $pkValue);
    }