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


PHP ClassMetadata::getIdentifierValues方法代码示例

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


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

示例1: getId

 /** {@inheritdoc} */
 public function getId($object)
 {
     if (!is_a($object, $this->getClass())) {
         throw new MetadataException("Object isn't subclass of '{$this->getClass()}', given '" . (is_object($object) ? get_class($object) : gettype($object)) . "'.");
     }
     $identifier = $this->classMetadata->getIdentifierValues($object);
     if (empty($identifier)) {
         return NULL;
     }
     return is_array($identifier) ? implode('_', $identifier) : $identifier;
 }
开发者ID:mike227,项目名称:n-forms,代码行数:12,代码来源:ClassMetadata.php

示例2: executeInserts

 /**
  * Executes all queued entity insertions and returns any generated post-insert
  * identifiers that were created as a result of the insertions.
  * 
  * If no inserts are queued, invoking this method is a NOOP.
  *
  * @return array An array of any generated post-insert IDs. This will be an empty array
  *               if the entity class does not use the IDENTITY generation strategy.
  */
 public function executeInserts()
 {
     if (!$this->_queuedInserts) {
         return;
     }
     $postInsertIds = array();
     $idGen = $this->_class->idGenerator;
     $isPostInsertId = $idGen->isPostInsertGenerator();
     $stmt = $this->_conn->prepare($this->getInsertSQL());
     $tableName = $this->_class->table['name'];
     foreach ($this->_queuedInserts as $entity) {
         $insertData = $this->_prepareInsertData($entity);
         if (isset($insertData[$tableName])) {
             $paramIndex = 1;
             foreach ($insertData[$tableName] as $column => $value) {
                 $stmt->bindValue($paramIndex++, $value, $this->_columnTypes[$column]);
             }
         }
         $stmt->execute();
         if ($isPostInsertId) {
             $id = $idGen->generate($this->_em, $entity);
             $postInsertIds[$id] = $entity;
         } else {
             $id = $this->_class->getIdentifierValues($entity);
         }
         if ($this->_class->isVersioned) {
             $this->_assignDefaultVersionValue($this->_class, $entity, $id);
         }
     }
     $stmt->closeCursor();
     $this->_queuedInserts = array();
     return $postInsertIds;
 }
开发者ID:poulikov,项目名称:readlater,代码行数:42,代码来源:StandardEntityPersister.php

示例3: exists

 /**
  * Checks whether the given managed entity exists in the database.
  *
  * @param object $entity
  * @return boolean TRUE if the entity exists in the database, FALSE otherwise.
  */
 public function exists($entity, array $extraConditions = array())
 {
     $criteria = $this->_class->getIdentifierValues($entity);
     if ($extraConditions) {
         $criteria = array_merge($criteria, $extraConditions);
     }
     $sql = 'SELECT 1 ' . $this->getLockTablesSql() . ' WHERE ' . $this->_getSelectConditionSQL($criteria);
     return (bool) $this->_conn->fetchColumn($sql, array_values($criteria));
 }
开发者ID:jfkz,项目名称:aquarel-cms,代码行数:15,代码来源:BasicEntityPersister.php

示例4: exists

 /**
  * Checks whether the given managed entity exists in the database.
  *
  * @param object $entity
  * @return boolean TRUE if the entity exists in the database, FALSE otherwise.
  */
 public function exists($entity, array $extraConditions = array())
 {
     $criteria = $this->_class->getIdentifierValues($entity);
     if ($extraConditions) {
         $criteria = array_merge($criteria, $extraConditions);
     }
     $sql = 'SELECT 1 FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($this->_class->name) . ' WHERE ' . $this->_getSelectConditionSQL($criteria);
     return (bool) $this->_conn->fetchColumn($sql, array_values($criteria));
 }
开发者ID:halljb57,项目名称:flextrine,代码行数:15,代码来源:BasicEntityPersister.php

示例5: exists

 /**
  * {@inheritdoc}
  */
 public function exists($entity, Criteria $extraConditions = null)
 {
     if (null === $extraConditions) {
         $key = new EntityCacheKey($this->class->rootEntityName, $this->class->getIdentifierValues($entity));
         if ($this->region->contains($key)) {
             return true;
         }
     }
     return $this->persister->exists($entity, $extraConditions);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:13,代码来源:AbstractEntityPersister.php

示例6: exists

 /**
  * {@inheritdoc}
  */
 public function exists($entity, array $extraConditions = array())
 {
     if (empty($extraConditions)) {
         $key = new EntityCacheKey($this->class->rootEntityName, $this->class->getIdentifierValues($entity));
         if ($this->region->contains($key)) {
             return true;
         }
     }
     return $this->persister->exists($entity, $extraConditions);
 }
开发者ID:svobodni,项目名称:web,代码行数:13,代码来源:AbstractEntityPersister.php

示例7: buildCacheEntry

 /**
  * {@inheritdoc}
  */
 public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $entity)
 {
     $data = $this->uow->getOriginalEntityData($entity);
     $data = array_merge($data, $metadata->getIdentifierValues($entity));
     // why update has no identifier values ?
     foreach ($metadata->associationMappings as $name => $assoc) {
         if (!isset($data[$name])) {
             continue;
         }
         if (!($assoc['type'] & ClassMetadata::TO_ONE)) {
             unset($data[$name]);
             continue;
         }
         if (!isset($assoc['cache'])) {
             $targetClassMetadata = $this->em->getClassMetadata($assoc['targetEntity']);
             $owningAssociation = !$assoc['isOwningSide'] ? $targetClassMetadata->associationMappings[$assoc['mappedBy']] : $assoc;
             $associationIds = $this->identifierFlattener->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($data[$name]));
             unset($data[$name]);
             foreach ($associationIds as $fieldName => $fieldValue) {
                 if (isset($targetClassMetadata->fieldMappings[$fieldName])) {
                     $fieldMapping = $targetClassMetadata->fieldMappings[$fieldName];
                     $data[$owningAssociation['targetToSourceKeyColumns'][$fieldMapping['columnName']]] = $fieldValue;
                     continue;
                 }
                 $targetAssoc = $targetClassMetadata->associationMappings[$fieldName];
                 foreach ($assoc['targetToSourceKeyColumns'] as $referencedColumn => $localColumn) {
                     if (isset($targetAssoc['sourceToTargetKeyColumns'][$referencedColumn])) {
                         $data[$localColumn] = $fieldValue;
                     }
                 }
             }
             continue;
         }
         if (!isset($assoc['id'])) {
             $targetClass = ClassUtils::getClass($data[$name]);
             $targetId = $this->uow->getEntityIdentifier($data[$name]);
             $data[$name] = new AssociationCacheEntry($targetClass, $targetId);
             continue;
         }
         // handle association identifier
         $targetId = is_object($data[$name]) && $this->uow->isInIdentityMap($data[$name]) ? $this->uow->getEntityIdentifier($data[$name]) : $data[$name];
         // @TODO - fix it !
         // handle UnitOfWork#createEntity hash generation
         if (!is_array($targetId)) {
             $data[reset($assoc['joinColumnFieldNames'])] = $targetId;
             $targetEntity = $this->em->getClassMetadata($assoc['targetEntity']);
             $targetId = [$targetEntity->identifier[0] => $targetId];
         }
         $data[$name] = new AssociationCacheEntry($assoc['targetEntity'], $targetId);
     }
     return new EntityCacheEntry($metadata->name, $data);
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:55,代码来源:DefaultEntityHydrator.php

示例8: exists

 /**
  * Checks whether the given managed entity exists in the database.
  *
  * @param object $entity
  * @return boolean TRUE if the entity exists in the database, FALSE otherwise.
  */
 public function exists($entity, array $extraConditions = array())
 {
     $criteria = $this->_class->getIdentifierValues($entity);
     if ($extraConditions) {
         $criteria = array_merge($criteria, $extraConditions);
     }
     $alias = $this->_getSQLTableAlias($this->_class->name);
     $sql = 'SELECT 1 ' . $this->getLockTablesSql() . ' WHERE ' . $this->_getSelectConditionSQL($criteria);
     if ($filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) {
         $sql .= ' AND ' . $filterSql;
     }
     list($params, $types) = $this->expandParameters($criteria);
     return (bool) $this->_conn->fetchColumn($sql, $params);
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:20,代码来源:BasicEntityPersister.php

示例9: createRecipientEntity

 /**
  * @param object $object
  * @param ClassMetadata $objectMetadata
  *
  * @return RecipientEntity
  */
 public function createRecipientEntity($object, ClassMetadata $objectMetadata)
 {
     $identifiers = $objectMetadata->getIdentifierValues($object);
     if (count($identifiers) !== 1) {
         return null;
     }
     $organizationName = null;
     if ($this->getPropertyAccessor()->isReadable($object, static::ORGANIZATION_PROPERTY)) {
         $organization = $this->getPropertyAccessor()->getValue($object, static::ORGANIZATION_PROPERTY);
         if ($organization) {
             $organizationName = $organization->getName();
         }
     }
     return new RecipientEntity($objectMetadata->name, reset($identifiers), $this->createRecipientEntityLabel($this->nameFormatter->format($object), $objectMetadata->name), $organizationName);
 }
开发者ID:Maksold,项目名称:platform,代码行数:21,代码来源:EmailRecipientsHelper.php

示例10: executeInserts

 /**
  * Executes all queued inserts.
  *
  * @return array An array of any generated post-insert IDs.
  */
 public function executeInserts()
 {
     if (!$this->_queuedInserts) {
         return;
     }
     $isVersioned = $this->_class->isVersioned;
     $postInsertIds = array();
     $idGen = $this->_class->idGenerator;
     $isPostInsertId = $idGen->isPostInsertGenerator();
     $stmt = $this->_conn->prepare($this->getInsertSQL());
     $primaryTableName = $this->_class->primaryTable['name'];
     foreach ($this->_queuedInserts as $entity) {
         $insertData = array();
         $this->_prepareData($entity, $insertData, true);
         if (isset($insertData[$primaryTableName])) {
             $paramIndex = 1;
             if ($this->_sqlLogger !== null) {
                 $params = array();
                 foreach ($insertData[$primaryTableName] as $value) {
                     $params[$paramIndex] = $value;
                     $stmt->bindValue($paramIndex++, $value);
                 }
                 $this->_sqlLogger->logSql($this->getInsertSQL(), $params);
             } else {
                 foreach ($insertData[$primaryTableName] as $value) {
                     $stmt->bindValue($paramIndex++, $value);
                 }
             }
         } else {
             if ($this->_sqlLogger !== null) {
                 $this->_sqlLogger->logSql($this->getInsertSQL());
             }
         }
         $stmt->execute();
         if ($isPostInsertId) {
             $id = $idGen->generate($this->_em, $entity);
             $postInsertIds[$id] = $entity;
         } else {
             $id = $this->_class->getIdentifierValues($entity);
         }
         if ($isVersioned) {
             $this->_assignDefaultVersionValue($this->_class, $entity, $id);
         }
     }
     $stmt->closeCursor();
     $this->_queuedInserts = array();
     return $postInsertIds;
 }
开发者ID:andreia,项目名称:doctrine,代码行数:53,代码来源:StandardEntityPersister.php

示例11: exists

 /**
  * {@inheritdoc}
  */
 public function exists($entity, Criteria $extraConditions = null)
 {
     $criteria = $this->class->getIdentifierValues($entity);
     if (!$criteria) {
         return false;
     }
     $alias = $this->getSQLTableAlias($this->class->name);
     $sql = 'SELECT 1 ' . $this->getLockTablesSql(null) . ' WHERE ' . $this->getSelectConditionSQL($criteria);
     list($params, $types) = $this->expandParameters($criteria);
     if (null !== $extraConditions) {
         $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions);
         list($criteriaParams, $criteriaTypes) = $this->expandCriteriaParameters($extraConditions);
         $params = array_merge($params, $criteriaParams);
         $types = array_merge($types, $criteriaTypes);
     }
     if ($filterSql = $this->generateFilterConditionSQL($this->class, $alias)) {
         $sql .= ' AND ' . $filterSql;
     }
     return (bool) $this->conn->fetchColumn($sql, $params, 0, $types);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:23,代码来源:BasicEntityPersister.php

示例12: hasAssociationChanged

 /**
  * @param ClassMetaData $association_meta
  * @param string        $left
  * @param string        $right
  * @return bool
  */
 private function hasAssociationChanged(ClassMetadata $association_meta, $left, $right)
 {
     // check if the PK of the related entity has changed (thus different link)
     if (null !== $left && null !== $right) {
         $left_values = $association_meta->getIdentifierValues($left);
         $right_values = $association_meta->getIdentifierValues($right);
         $diff = array_udiff($left_values, $right_values, function ($a, $b) {
             // note that equal returns 0, difference should return -1 or 1
             if (!is_object($a) && !is_object($b)) {
                 return (string) $a === (string) $b ? 0 : 1;
             }
             // prevent casting objects to strings
             return $a === $b ? 0 : 1;
         });
         if (!empty($diff)) {
             $this->logger->info('Association Change detected on owning ONE side', ['left' => $left_values, 'right' => $right_values]);
             return true;
         }
     }
     return $left != $right;
 }
开发者ID:hostnet,项目名称:entity-tracker-component,代码行数:27,代码来源:EntityMutationMetadataProvider.php

示例13:

 function it_should_throw_an_exception_if_there_is_not_exactly_one_identity_value(DefinitionInterface $definition, ClassMetadata $metadata, \stdClass $object)
 {
     $metadata->getIdentifierValues($object)->willReturn([1, 2, 3]);
     $this->shouldThrow('Bravesheep\\CrudifyBundle\\Exception\\UnsupportedEntityException')->duringGetId($definition, $object);
 }
开发者ID:bravesheep,项目名称:crudify-bundle,代码行数:5,代码来源:IdentityResolverSpec.php


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