コード例 #1
0
ファイル: ClassMetadata.php プロジェクト: cosmow/riak-odm
 /**
  * Map a field.
  *
  * @param array $mapping The mapping information.
  * @return void
  */
 public function mapField(array $mapping)
 {
     $mapping = parent::mapField($mapping);
     if ($this->reflClass->hasProperty($mapping['fieldName'])) {
         $reflProp = $this->reflClass->getProperty($mapping['fieldName']);
         $reflProp->setAccessible(true);
         $this->reflFields[$mapping['fieldName']] = $reflProp;
     }
 }
コード例 #2
0
ファイル: YamlDriver.php プロジェクト: cosmow/riak-odm
 private function addFieldMapping(ClassMetadataInfo $class, $mapping)
 {
     if (isset($mapping['name'])) {
         $name = $mapping['name'];
     } elseif (isset($mapping['fieldName'])) {
         $name = $mapping['fieldName'];
     } else {
         throw new \InvalidArgumentException('Cannot infer a Riak name from the mapping');
     }
     $class->mapField($mapping);
     if (!(isset($mapping['index']) || isset($mapping['unique']) || isset($mapping['sparse']))) {
         return;
     }
     // Multiple index specifications in one field mapping is ambiguous
     if ((isset($mapping['index']) && is_array($mapping['index'])) + (isset($mapping['unique']) && is_array($mapping['unique'])) + (isset($mapping['sparse']) && is_array($mapping['sparse'])) > 1) {
         throw new \InvalidArgumentException('Multiple index specifications found among index, unique, and/or sparse fields');
     }
     // Index this field if either "index", "unique", or "sparse" are set
     $keys = array($name => 'asc');
     /* The "order" option is only used in the index specification and should
      * not be passed along as an index option.
      */
     if (isset($mapping['index']['order'])) {
         $keys[$name] = $mapping['index']['order'];
         unset($mapping['index']['order']);
     } elseif (isset($mapping['unique']['order'])) {
         $keys[$name] = $mapping['unique']['order'];
         unset($mapping['unique']['order']);
     } elseif (isset($mapping['sparse']['order'])) {
         $keys[$name] = $mapping['sparse']['order'];
         unset($mapping['sparse']['order']);
     }
     /* Initialize $options from any array value among index, unique, and
      * sparse. Any boolean values for unique or sparse should be merged into
      * the options afterwards to ensure consistent parsing.
      */
     $options = array();
     $unique = null;
     $sparse = null;
     if (isset($mapping['index']) && is_array($mapping['index'])) {
         $options = $mapping['index'];
     }
     if (isset($mapping['unique'])) {
         if (is_array($mapping['unique'])) {
             $options = $mapping['unique'] + array('unique' => true);
         } else {
             $unique = (bool) $mapping['unique'];
         }
     }
     if (isset($mapping['sparse'])) {
         if (is_array($mapping['sparse'])) {
             $options = $mapping['sparse'] + array('sparse' => true);
         } else {
             $sparse = (bool) $mapping['sparse'];
         }
     }
     if (isset($unique)) {
         $options['unique'] = $unique;
     }
     if (isset($sparse)) {
         $options['sparse'] = $sparse;
     }
     $class->addIndex($keys, $options);
 }
コード例 #3
0
ファイル: XmlDriver.php プロジェクト: cosmow/riak-odm
 private function addFieldMapping(ClassMetadataInfo $class, $mapping)
 {
     if (isset($mapping['name'])) {
         $name = $mapping['name'];
     } elseif (isset($mapping['fieldName'])) {
         $name = $mapping['fieldName'];
     } else {
         throw new \InvalidArgumentException('Cannot infer a Riak name from the mapping');
     }
     $class->mapField($mapping);
     // Index this field if either "index", "unique", or "sparse" are set
     if (!(isset($mapping['index']) || isset($mapping['unique']) || isset($mapping['sparse']))) {
         return;
     }
     $keys = array($name => isset($mapping['order']) ? $mapping['order'] : 'asc');
     $options = array();
     if (isset($mapping['background'])) {
         $options['background'] = (bool) $mapping['background'];
     }
     if (isset($mapping['drop-dups'])) {
         $options['dropDups'] = (bool) $mapping['drop-dups'];
     }
     if (isset($mapping['index-name'])) {
         $options['name'] = (string) $mapping['index-name'];
     }
     if (isset($mapping['safe'])) {
         $options['safe'] = (bool) $mapping['safe'];
     }
     if (isset($mapping['sparse'])) {
         $options['sparse'] = (bool) $mapping['sparse'];
     }
     if (isset($mapping['unique'])) {
         $options['unique'] = (bool) $mapping['unique'];
     }
     $class->addIndex($keys, $options);
 }