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


PHP ClassMetadata::hasDiscriminator方法代码示例

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


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

示例1: addDiscriminatorToPreparedQuery

 /**
  * Adds discriminator criteria to an already-prepared query.
  *
  * This method should be used once for query criteria and not be used for
  * nested expressions. It should be called before
  * {@link DocumentPerister::addFilterToPreparedQuery()}.
  *
  * @param array $preparedQuery
  * @return array
  */
 public function addDiscriminatorToPreparedQuery(array $preparedQuery)
 {
     /* If the class has a discriminator field, which is not already in the
      * criteria, inject it now. The field/values need no preparation.
      */
     if ($this->class->hasDiscriminator() && !isset($preparedQuery[$this->class->discriminatorField])) {
         $discriminatorValues = $this->getClassDiscriminatorValues($this->class);
         $preparedQuery[$this->class->discriminatorField] = array('$in' => $discriminatorValues);
     }
     return $preparedQuery;
 }
开发者ID:im286er,项目名称:ent,代码行数:21,代码来源:DocumentPersister.php

示例2: prepareInsertData

 /**
  * Prepares insert data for document
  *
  * @param mixed $document
  * @return array
  */
 public function prepareInsertData($document)
 {
     $oid = spl_object_hash($document);
     $changeset = $this->uow->getDocumentChangeSet($document);
     $insertData = array();
     foreach ($this->class->fieldMappings as $mapping) {
         if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) {
             continue;
         }
         $new = isset($changeset[$mapping['fieldName']][1]) ? $changeset[$mapping['fieldName']][1] : null;
         if ($new === null && $mapping['nullable'] === false) {
             continue;
         }
         if ($this->class->isIdentifier($mapping['fieldName'])) {
             $insertData['_id'] = $this->prepareValue($mapping, $new);
             continue;
         }
         $value = $this->prepareValue($mapping, $new);
         if ($value === null && $mapping['nullable'] === false) {
             continue;
         }
         $insertData[$mapping['name']] = $value;
         if (isset($mapping['reference'])) {
             $scheduleForUpdate = false;
             if ($mapping['type'] === 'one') {
                 if (!isset($insertData[$mapping['name']][$this->cmd . 'id'])) {
                     $scheduleForUpdate = true;
                 }
             } elseif ($mapping['type'] === 'many') {
                 foreach ($insertData[$mapping['name']] as $ref) {
                     if (!isset($ref[$this->cmd . 'id'])) {
                         $scheduleForUpdate = true;
                         break;
                     }
                 }
             }
             if ($scheduleForUpdate) {
                 unset($insertData[$mapping['name']]);
                 $id = spl_object_hash($document);
                 $this->documentsToUpdate[$id] = $document;
                 $this->fieldsToUpdate[$id][$mapping['fieldName']] = array($mapping, $new);
             }
         }
     }
     // add discriminator if the class has one
     if ($this->class->hasDiscriminator()) {
         $insertData[$this->class->discriminatorField['name']] = $this->class->discriminatorValue;
     }
     return $insertData;
 }
开发者ID:roydonstharayil,项目名称:sugarbox,代码行数:56,代码来源:BasicDocumentPersister.php

示例3: prepareQuery

 /**
  * Prepares a query and converts values to the types mongodb expects.
  *
  * @param string|array $query
  * @return array $query
  */
 public function prepareQuery($query)
 {
     if (is_scalar($query)) {
         $query = array('_id' => $query);
     }
     if ($this->class->hasDiscriminator() && !isset($query[$this->class->discriminatorField['name']])) {
         $discriminatorValues = $this->getClassDiscriminatorValues($this->class);
         $query[$this->class->discriminatorField['name']] = array('$in' => $discriminatorValues);
     }
     $newQuery = array();
     foreach ($query as $key => $value) {
         $value = $this->prepareQueryValue($key, $value);
         $newQuery[$key] = $value;
     }
     return $newQuery;
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:22,代码来源:DocumentPersister.php

示例4: prepareQuery

 /**
  * Prepares a query array by converting the portable Doctrine types to the types mongodb expects.
  *
  * @param string|array $query
  * @return array $newQuery
  */
 public function prepareQuery($query)
 {
     if (is_scalar($query) || $query instanceof \MongoId) {
         $query = array('_id' => $query);
     }
     if ($this->class->hasDiscriminator() && !isset($query[$this->class->discriminatorField['name']])) {
         $discriminatorValues = $this->getClassDiscriminatorValues($this->class);
         $query[$this->class->discriminatorField['name']] = array('$in' => $discriminatorValues);
     }
     $newQuery = array();
     if ($query) {
         foreach ($query as $key => $value) {
             if (isset($key[0]) && $key[0] === $this->cmd && is_array($value)) {
                 $newQuery[$key] = $this->prepareSubQuery($value);
             } else {
                 $newQuery[$key] = $this->prepareQueryElement($key, $value, null, true);
             }
         }
         $newQuery = $this->convertTypes($newQuery);
     }
     return $newQuery;
 }
开发者ID:ud223,项目名称:yj,代码行数:28,代码来源:DocumentPersister.php

示例5: serializeClassNameAndDiscriminator

 protected function serializeClassNameAndDiscriminator(ClassMetadata $metadata)
 {
     $return = array();
     if (isset($metadata->serializer['className']) && $metadata->serializer['className']) {
         $return[$this->classNameField] = $metadata->name;
     }
     if (isset($metadata->serializer['discriminator']) && $metadata->serializer['discriminator'] && $metadata->hasDiscriminator()) {
         $return[$metadata->discriminatorField['name']] = $metadata->discriminatorValue;
     }
     return $return;
 }
开发者ID:superdweebie,项目名称:doctrine-extensions,代码行数:11,代码来源:Serializer.php


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