本文整理汇总了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]]);
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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();
}
示例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;
}