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


PHP ClassMetadata::getDatabaseIdentifierValue方法代码示例

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


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

示例1: prepareQueryValue

 /**
  * Prepares a query value and converts the php value to the database value if it is an identifier.
  * It also handles converting $fieldName to the database name if they are different.
  *
  * @param string $fieldName
  * @param string $value
  * @return mixed $value
  */
 private function prepareQueryValue(&$fieldName, $value)
 {
     // Process "association.fieldName"
     if (strpos($fieldName, '.') !== false) {
         $e = explode('.', $fieldName);
         $mapping = $this->class->getFieldMapping($e[0]);
         if ($this->class->hasField($e[0])) {
             $name = $this->class->fieldMappings[$e[0]]['name'];
             if ($name !== $e[0]) {
                 $e[0] = $name;
             }
         }
         if (isset($mapping['targetDocument'])) {
             $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
             if ($targetClass->hasField($e[1])) {
                 if ($targetClass->identifier === $e[1] || $e[1] === '$id') {
                     $fieldName = $e[0] . '.$id';
                     $value = $targetClass->getDatabaseIdentifierValue($value);
                 }
             }
         }
         // Process all non identifier fields
     } elseif ($this->class->hasField($fieldName) && !$this->class->isIdentifier($fieldName)) {
         $name = $this->class->fieldMappings[$fieldName]['name'];
         $mapping = $this->class->fieldMappings[$fieldName];
         if ($name !== $fieldName) {
             $fieldName = $name;
         }
         // Process identifier
     } elseif ($fieldName === $this->class->identifier || $fieldName === '_id') {
         $fieldName = '_id';
         $value = $this->class->getDatabaseIdentifierValue($value);
     }
     return $value;
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:43,代码来源:DocumentPersister.php

示例2: prepareQueryValue

 /**
  * Prepares a query value and converts the php value to the database value if it is an identifier.
  * It also handles converting $fieldName to the database name if they are different.
  *
  * @param string $fieldName
  * @param string $value
  * @return mixed $value
  */
 private function prepareQueryValue(&$fieldName, $value)
 {
     // Process "association.fieldName"
     if (strpos($fieldName, '.') !== false) {
         $e = explode('.', $fieldName);
         $mapping = $this->class->getFieldMapping($e[0]);
         $name = $mapping['name'];
         if ($name !== $e[0]) {
             $e[0] = $name;
         }
         if (isset($mapping['targetDocument'])) {
             $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
             if ($targetClass->hasField($e[1])) {
                 if ($targetClass->identifier === $e[1]) {
                     $e[1] = '$id';
                     if (is_array($value)) {
                         foreach ($value as $k => $v) {
                             $value[$k] = $targetClass->getDatabaseIdentifierValue($v);
                         }
                     } else {
                         $value = $targetClass->getDatabaseIdentifierValue($value);
                     }
                 } else {
                     $targetMapping = $targetClass->getFieldMapping($e[1]);
                     $targetName = $targetMapping['name'];
                     if ($targetName !== $e[1]) {
                         $e[1] = $targetName;
                     }
                 }
                 $fieldName = $e[0] . '.' . $e[1];
             }
         }
         // Process all non identifier fields
         // We only change the field names here to the mongodb field name used for persistence
     } elseif ($this->class->hasField($fieldName) && !$this->class->isIdentifier($fieldName)) {
         $name = $this->class->fieldMappings[$fieldName]['name'];
         $mapping = $this->class->fieldMappings[$fieldName];
         if ($name !== $fieldName) {
             $fieldName = $name;
         }
         // Process identifier
     } elseif ($this->class->hasField($fieldName) && $this->class->isIdentifier($fieldName) || $fieldName === '_id') {
         $fieldName = '_id';
         if (is_array($value)) {
             foreach ($value as $k => $v) {
                 if ($k[0] === '$' && is_array($v)) {
                     foreach ($v as $k2 => $v2) {
                         $value[$k][$k2] = $this->class->getDatabaseIdentifierValue($v2);
                     }
                 } else {
                     $value[$k] = $this->class->getDatabaseIdentifierValue($v);
                 }
             }
         } else {
             $value = $this->class->getDatabaseIdentifierValue($value);
         }
     }
     return $value;
 }
开发者ID:nextmotion,项目名称:mongodb-odm,代码行数:67,代码来源:DocumentPersister.php

示例3: unlock

 /**
  * Releases any lock that exists on this document.
  *
  * @param object $document
  */
 public function unlock($document)
 {
     $id = $this->uow->getDocumentIdentifier($document);
     $criteria = array('_id' => $this->class->getDatabaseIdentifierValue($id));
     $lockMapping = $this->class->fieldMappings[$this->class->lockField];
     $this->collection->update($criteria, array($this->cmd . 'unset' => array($lockMapping['name'] => true)));
     $this->class->reflFields[$this->class->lockField]->setValue($document, null);
 }
开发者ID:3116246,项目名称:haolinju,代码行数:13,代码来源:DocumentPersister.php

示例4: loadById

 /**
  * Lood document by its identifier.
  *
  * @param string $id
  * @return object|null
  */
 public function loadById($id)
 {
     $result = $this->collection->findOne(array('_id' => $this->class->getDatabaseIdentifierValue($id)));
     if ($result !== null) {
         return $this->uow->getOrCreateDocument($this->documentName, $result);
     }
     return null;
 }
开发者ID:roydonstharayil,项目名称:sugarbox,代码行数:14,代码来源:BasicDocumentPersister.php

示例5: getQueryForDocument

 /**
  * Get shard key aware query for single document.
  *
  * @param object $document
  *
  * @return array
  */
 private function getQueryForDocument($document)
 {
     $id = $this->uow->getDocumentIdentifier($document);
     $id = $this->class->getDatabaseIdentifierValue($id);
     $shardKeyQueryPart = $this->getShardKeyQuery($document);
     $query = array_merge(array('_id' => $id), $shardKeyQueryPart);
     return $query;
 }
开发者ID:dominium,项目名称:mongodb-odm,代码行数:15,代码来源:DocumentPersister.php

示例6: loadById

 /**
  * Lood document by its identifier.
  *
  * @param string $id
  * @return object|null
  */
 public function loadById($id)
 {
     $result = $this->_collection->findOne(array('_id' => $this->_class->getDatabaseIdentifierValue($id)));
     if ($result !== null) {
         $document = $this->_uow->getOrCreateDocument($this->_documentName, $result);
         $this->_uow->registerManaged($document, $this->_class->getPHPIdentifierValue($result['_id']), $result);
         return $document;
     }
     return null;
 }
开发者ID:klaasn,项目名称:symfony-sandbox,代码行数:16,代码来源:BasicDocumentPersister.php

示例7: prepareWhereValue

    /**
     * Prepare where values converting document object field names to the document collection
     * field name.
     *
     * @param string $fieldName
     * @param string $value
     * @return string $value
     */
    private function prepareWhereValue(&$fieldName, $value)
    {
        if (strpos($fieldName, '.') !== false) {
            $e = explode('.', $fieldName);

            $mapping = $this->class->getFieldMapping($e[0]);

            if ($this->class->hasField($e[0])) {
                $name = $this->class->fieldMappings[$e[0]]['name'];
                if ($name !== $e[0]) {
                    $e[0] = $name;
                }
            }

            if (isset($mapping['targetDocument'])) {
                $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
                if ($targetClass->hasField($e[1]) && $targetClass->identifier === $e[1]) {
                    $fieldName = $e[0] . '.$id';
                    $value = $targetClass->getDatabaseIdentifierValue($value);
                } elseif ($e[1] === '$id') {
                    $value = $targetClass->getDatabaseIdentifierValue($value);
                }
            }
        } elseif ($this->class->hasField($fieldName) && ! $this->class->isIdentifier($fieldName)) {
            $name = $this->class->fieldMappings[$fieldName]['name'];
            if ($name !== $fieldName) {
                $fieldName = $name;
            }
        } else {
            if ($fieldName === $this->class->identifier || $fieldName === '_id') {
                $fieldName = '_id';
                if (is_array($value)) {
                    if (isset($value[$this->cmd.'in'])) {
                        foreach ($value[$this->cmd.'in'] as $k => $v) {
                            $value[$this->cmd.'in'][$k] = $this->class->getDatabaseIdentifierValue($v);
                        }
                    } else {
                        foreach ($value as $k => $v) {
                            $value[$k] = $this->class->getDatabaseIdentifierValue($v);
                        }
                    }
                } else {
                    $value = $this->class->getDatabaseIdentifierValue($value);
                }
            }
        }
        return $value;
    }
开发者ID:pmjones,项目名称:php-framework-benchmarks,代码行数:56,代码来源:DocumentPersister.php

示例8: tryGetById

 /**
  * INTERNAL:
  * Tries to get a document by its identifier hash. If no document is found
  * for the given hash, FALSE is returned.
  *
  * @ignore
  * @param mixed         $id    Document identifier
  * @param ClassMetadata $class Document class
  * @return mixed The found document or FALSE.
  * @throws InvalidArgumentException if the class does not have an identifier
  */
 public function tryGetById($id, ClassMetadata $class)
 {
     if (!$class->identifier) {
         throw new \InvalidArgumentException(sprintf('Class "%s" does not have an identifier', $class->name));
     }
     $serializedId = serialize($class->getDatabaseIdentifierValue($id));
     return isset($this->identityMap[$class->name][$serializedId]) ? $this->identityMap[$class->name][$serializedId] : false;
 }
开发者ID:kevinyien,项目名称:mongodb-odm,代码行数:19,代码来源:UnitOfWork.php

示例9: prepareQueryExpression

 /**
  * Prepares a query expression.
  *
  * @param array|object  $expression
  * @param ClassMetadata $class
  * @return array
  */
 private function prepareQueryExpression($expression, $class)
 {
     foreach ($expression as $k => $v) {
         // Ignore query operators whose arguments need no type conversion
         if (in_array($k, array('$exists', '$type', '$mod', '$size'))) {
             continue;
         }
         // Process query operators whose argument arrays need type conversion
         if (in_array($k, array('$in', '$nin', '$all')) && is_array($v)) {
             foreach ($v as $k2 => $v2) {
                 $expression[$k][$k2] = $class->getDatabaseIdentifierValue($v2);
             }
             continue;
         }
         // Recursively process expressions within a $not operator
         if ($k === '$not' && is_array($v)) {
             $expression[$k] = $this->prepareQueryExpression($v, $class);
             continue;
         }
         $expression[$k] = $class->getDatabaseIdentifierValue($v);
     }
     return $expression;
 }
开发者ID:ttk04,项目名称:mongodb-odm,代码行数:30,代码来源:DocumentPersister.php

示例10: getDocumentId

 /**
  * Gets the document database identifier value for the given document.
  *
  * @param object $document
  * @param ClassMetadata $class
  * @return mixed $id
  */
 private function getDocumentId($document, ClassMetadata $class)
 {
     return $class->getDatabaseIdentifierValue($this->uow->getDocumentIdentifier($document));
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:11,代码来源:CollectionPersister.php

示例11: tryGetById

 /**
  * INTERNAL:
  * Tries to get a document by its identifier hash. If no document is found
  * for the given hash, FALSE is returned.
  *
  * @ignore
  * @param mixed         $id    Document identifier
  * @param ClassMetadata $class Document class
  * @return mixed The found document or FALSE.
  * @throws InvalidArgumentException if the class does not have an identifier
  */
 public function tryGetById($id, ClassMetadata $class)
 {
     if (!$class->identifier) {
         throw new \InvalidArgumentException(sprintf('Class "%s" does not have an identifier', $class->name));
     }
     $serializedId = serialize($class->getDatabaseIdentifierValue($id));
     /* Trying all the classes from the discriminator map as well
      * to avoid issuing extra DB query in case of using simple reference.
      */
     foreach ($class->discriminatorMap as $className) {
         // Never return parent instances, only children
         if (in_array($className, $class->parentClasses)) {
             continue;
         }
         if (isset($this->identityMap[$className][$serializedId])) {
             return $this->identityMap[$className][$serializedId];
         }
     }
     return isset($this->identityMap[$class->name][$serializedId]) ? $this->identityMap[$class->name][$serializedId] : false;
 }
开发者ID:briareos,项目名称:mongodb-odm,代码行数:31,代码来源:UnitOfWork.php


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