当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadata::getReflectionProperty方法代码示例

本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::getReflectionProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getReflectionProperty方法的具体用法?PHP ClassMetadata::getReflectionProperty怎么用?PHP ClassMetadata::getReflectionProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::getReflectionProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateField

 /**
  * Updates a field
  *
  * @param ORM\UnitOfWork $uow
  * @param mixed $object
  * @param ORM\Mapping\ClassMetadata $classMetadata
  * @param string $field
  */
 private function updateField(ORM\UnitOfWork $uow, $object, ORM\Mapping\ClassMetadata $classMetadata, $field)
 {
     $property = $classMetadata->getReflectionProperty($field);
     $oldValue = $property->getValue($object);
     $newValue = $this->getDateValue($classMetadata, $field);
     $property->setValue($object, $newValue);
     $uow->propertyChanged($object, $field, $oldValue, $newValue);
     $uow->scheduleExtraUpdate($object, [$field => [$oldValue, $newValue]]);
 }
开发者ID:iPublikuj,项目名称:doctrine-timestampable,代码行数:17,代码来源:TimestampableSubscriber.php

示例2: calculateManyToOneData

 /**
  * @param DoctrineClassMetadata $entityMeta
  * @param object                $entity
  *
  * @return array [entityIdentifier => entity, ...]
  */
 protected function calculateManyToOneData(DoctrineClassMetadata $entityMeta, $entity)
 {
     $entities = [];
     foreach ($entityMeta->associationMappings as $assoc) {
         if ($assoc['type'] !== DoctrineClassMetadata::MANY_TO_ONE || empty($assoc['inversedBy'])) {
             continue;
         }
         $owner = $entityMeta->getReflectionProperty($assoc['fieldName'])->getValue($entity);
         if (!$owner) {
             continue;
         }
         $ownerMeta = $this->em->getClassMetadata($assoc['targetEntity']);
         $collection = $ownerMeta->getReflectionProperty($assoc['inversedBy'])->getValue($owner);
         if (!$collection instanceof PersistentCollection) {
             continue;
         }
         $entityIdentifier = $this->getEntityIdentifierString($owner);
         $this->calculateCollectionData($collection, $entityIdentifier);
         $entities[$entityIdentifier] = $owner;
     }
     return $entities;
 }
开发者ID:Maksold,项目名称:platform,代码行数:28,代码来源:LoggableManager.php

示例3: calculateManyToOneData

 /**
  * @param DoctrineClassMetadata $entityMeta
  * @param object $entity
  */
 protected function calculateManyToOneData(DoctrineClassMetadata $entityMeta, $entity)
 {
     $requiredProperties = array_flip(['type', 'fieldName', 'targetEntity', 'inversedBy']);
     foreach ($entityMeta->associationMappings as $assoc) {
         if (count($requiredProperties) !== count(array_filter(array_intersect_key($assoc, $requiredProperties)))) {
             continue;
         }
         if ($assoc['type'] !== DoctrineClassMetadata::MANY_TO_ONE) {
             continue;
         }
         $owner = $entityMeta->getReflectionProperty($assoc['fieldName'])->getValue($entity);
         if (!$owner) {
             continue;
         }
         $ownerMeta = $this->em->getClassMetadata($assoc['targetEntity']);
         $collection = $ownerMeta->getReflectionProperty($assoc['inversedBy'])->getValue($owner);
         if (!$collection instanceof PersistentCollection) {
             continue;
         }
         $entityIdentifier = $this->getEntityIdentifierString($owner);
         $this->calculateCollectionData($collection, $entityIdentifier);
         $this->updatedEntities[$entityIdentifier] = $owner;
     }
 }
开发者ID:anyt,项目名称:platform,代码行数:28,代码来源:LoggableManager.php

示例4: handleField

 /**
  * @param $entity
  * @param string $method
  * @param array $column
  * @param ClassMetadata $meta
  */
 protected function handleField($entity, $method, array $column, $meta)
 {
     $field = $column['field'];
     $oid = spl_object_hash($entity);
     $reflProp = $meta->getReflectionProperty($field);
     $oldValue = $this->getEntityValue($reflProp, $entity);
     $newValue = $this->getNewValue($oid, $field, $column['name'], $method, $oldValue);
     $reflProp->setValue($entity, $newValue);
     if ($method === self::FUNCTION_REVERSE_TRANSFORM) {
         $this->storeOriginalFieldData($oid, $field, $oldValue, $newValue);
     }
 }
开发者ID:mediamonks,项目名称:doctrine-extensions,代码行数:18,代码来源:TransformableSubscriber.php

示例5: saveNodeTree

 /**
  * Save the tree hierarchy for the specified node.
  *
  * @param EntityManager $entityManager
  * @param object $entity The node to save the tree for.
  * @param ClassMetadata $nodeMetadata
  * @param object|null $parent The parent entity (or null to get it from the entity itself).
  */
 protected function saveNodeTree(EntityManager $entityManager, $entity, ClassMetadata $nodeMetadata, $parent = null)
 {
     $nodeClass = get_class($entity);
     $treeClass = $nodeMetadata->closureTree['treeEntity'];
     // Get metadata
     $treeMetadata = $entityManager->getClassMetadata($treeClass);
     // Get the table name
     $tableName = $treeMetadata->getTableName();
     $idColumn = $nodeMetadata->getSingleIdentifierFieldName();
     $ancestorColumn = $treeMetadata->closureTree['ancestor']['fieldName'];
     $descendantColumn = $treeMetadata->closureTree['descendant']['fieldName'];
     if ($treeMetadata->closureTree['depth']) {
         $depthColumn = $treeMetadata->closureTree['depth']['fieldName'];
     } else {
         $depthColumn = null;
     }
     $nodeId = $nodeMetadata->getReflectionProperty($idColumn)->getValue($entity);
     $parent = $parent ?: $entity->getParent();
     // Check if the entity has a parent
     if ($parent) {
         // Get the parent ID
         $parentId = $parent->getId();
         // Format the query to insert the tree hierarchy
         $query = 'INSERT INTO ' . $tableName . ' (' . $ancestorColumn . ', ' . $descendantColumn;
         if ($depthColumn) {
             $query .= ', ' . $depthColumn;
         }
         $query .= ') SELECT ' . $ancestorColumn . ', ' . $nodeId . ' ';
         if ($depthColumn) {
             $query .= ', (' . $depthColumn . ' + 1) ';
         }
         $query .= 'FROM ' . $tableName . ' ';
         $query .= 'WHERE ' . $descendantColumn . ' = ? ';
         $query .= 'UNION ALL SELECT ' . $nodeId . ', ' . $nodeId;
         if ($depthColumn) {
             $query .= ', 0';
         }
         // Set the query parameters
         $queryParams = array($parentId);
     } else {
         // Format the query to insert the tree hierarchy
         $query = 'INSERT INTO ' . $tableName . ' ';
         $query .= '(' . $ancestorColumn . ', ' . $descendantColumn;
         if ($depthColumn) {
             $query .= ', ' . $depthColumn;
         }
         $query .= ') VALUES (?, ?';
         if ($depthColumn) {
             $query .= ', 0';
         }
         $query .= ')';
         // Set the query parameters
         $queryParams = array($nodeId, $nodeId);
     }
     // Execute the query and close the cursor
     $entityManager->getConnection()->executeQuery($query, $queryParams)->closeCursor();
 }
开发者ID:theartoflogic,项目名称:doctrine-tree-extension,代码行数:65,代码来源:EventSubscriber.php

示例6: allowPersist

 public function allowPersist(ClassMetadata $cm, $field)
 {
     $groupsAnnotation = $this->reader->getPropertyAnnotation($cm->getReflectionProperty($field), 'Symfony\\Component\\Serializer\\Annotation\\Groups');
     if ($groupsAnnotation !== null) {
         if (in_array("readonly", $groupsAnnotation->getGroups())) {
             return false;
         }
     }
     return true;
 }
开发者ID:partkeepr,项目名称:PartKeepr,代码行数:10,代码来源:ReflectionService.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadata::getReflectionProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。