Пример #1
0
 public function getFieldsMetadata($class)
 {
     $result = array();
     foreach ($this->odmMetadata->getReflectionProperties() as $property) {
         $name = $property->getName();
         $mapping = $this->odmMetadata->getFieldMapping($name);
         $values = array('title' => $name, 'source' => true);
         if (isset($mapping['fieldName'])) {
             $values['field'] = $mapping['fieldName'];
         }
         if (isset($mapping['id']) && $mapping['id'] == 'id') {
             $values['primary'] = true;
         }
         switch ($mapping['type']) {
             case 'id':
             case 'int':
             case 'string':
             case 'float':
             case 'many':
                 $values['type'] = 'text';
                 break;
             case 'boolean':
                 $values['type'] = 'boolean';
                 break;
             case 'date':
                 $values['type'] = 'date';
                 break;
         }
         $result[$name] = $values;
     }
     return $result;
 }
Пример #2
0
 public function getFieldsMetadata($class, $group = 'default')
 {
     $result = array();
     foreach ($this->odmMetadata->getReflectionProperties() as $property) {
         $name = $property->getName();
         $mapping = $this->odmMetadata->getFieldMapping($name);
         $values = array('title' => $name, 'source' => true);
         if (isset($mapping['fieldName'])) {
             $values['field'] = $mapping['fieldName'];
             $values['id'] = $mapping['fieldName'];
         }
         if (isset($mapping['id']) && $mapping['id'] == 'id') {
             $values['primary'] = true;
         }
         switch ($mapping['type']) {
             case 'id':
             case 'string':
             case 'bin_custom':
             case 'bin_func':
             case 'bin_md5':
             case 'bin':
             case 'bin_uuid':
             case 'file':
             case 'key':
             case 'increment':
                 $values['type'] = 'text';
                 break;
             case 'int':
             case 'float':
                 $values['type'] = 'number';
                 break;
                 /*case 'hash':
                   $values['type'] = 'array';*/
             /*case 'hash':
               $values['type'] = 'array';*/
             case 'boolean':
                 $values['type'] = 'boolean';
                 break;
             case 'date':
             case 'timestamp':
                 $values['type'] = 'date';
                 break;
             case 'collection':
                 $values['type'] = 'array';
                 break;
             case 'one':
                 $values['type'] = 'array';
                 break;
             case 'many':
                 $values['type'] = 'array';
                 break;
             default:
                 $values['type'] = 'text';
         }
         $result[$name] = $values;
     }
     return $result;
 }
Пример #3
0
 public function testClassMetadataInstanceSerialization()
 {
     $cm = new ClassMetadata('Documents\\CmsUser');
     // Test initial state
     $this->assertTrue(count($cm->getReflectionProperties()) == 0);
     $this->assertTrue($cm->reflClass instanceof \ReflectionClass);
     $this->assertEquals('Documents\\CmsUser', $cm->name);
     $this->assertEquals('Documents\\CmsUser', $cm->rootDocumentName);
     $this->assertEquals(array(), $cm->subClasses);
     $this->assertEquals(array(), $cm->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm->inheritanceType);
     // Customize state
     $cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION);
     $cm->setSubclasses(array("One", "Two", "Three"));
     $cm->setParentClasses(array("UserParent"));
     $cm->setCustomRepositoryClass("UserRepository");
     $cm->setDiscriminatorField('disc');
     $cm->mapOneEmbedded(array('fieldName' => 'phonenumbers', 'targetDocument' => 'Bar'));
     $cm->setFile('customFileProperty');
     $cm->setDistance('customDistanceProperty');
     $cm->setSlaveOkay(true);
     $cm->setShardKey(array('_id' => '1'));
     $cm->setCollectionCapped(true);
     $cm->setCollectionMax(1000);
     $cm->setCollectionSize(500);
     $this->assertTrue(is_array($cm->getFieldMapping('phonenumbers')));
     $this->assertEquals(1, count($cm->fieldMappings));
     $this->assertEquals(1, count($cm->associationMappings));
     $serialized = serialize($cm);
     $cm = unserialize($serialized);
     // Check state
     $this->assertTrue(count($cm->getReflectionProperties()) > 0);
     $this->assertEquals('Documents', $cm->namespace);
     $this->assertTrue($cm->reflClass instanceof \ReflectionClass);
     $this->assertEquals('Documents\\CmsUser', $cm->name);
     $this->assertEquals('UserParent', $cm->rootDocumentName);
     $this->assertEquals(array('Documents\\One', 'Documents\\Two', 'Documents\\Three'), $cm->subClasses);
     $this->assertEquals(array('UserParent'), $cm->parentClasses);
     $this->assertEquals('Documents\\UserRepository', $cm->customRepositoryClassName);
     $this->assertEquals('disc', $cm->discriminatorField);
     $this->assertTrue(is_array($cm->getFieldMapping('phonenumbers')));
     $this->assertEquals(1, count($cm->fieldMappings));
     $this->assertEquals(1, count($cm->associationMappings));
     $this->assertEquals('customFileProperty', $cm->file);
     $this->assertEquals('customDistanceProperty', $cm->distance);
     $this->assertTrue($cm->slaveOkay);
     $this->assertEquals(array('keys' => array('_id' => 1), 'options' => array()), $cm->getShardKey());
     $mapping = $cm->getFieldMapping('phonenumbers');
     $this->assertEquals('Documents\\Bar', $mapping['targetDocument']);
     $this->assertTrue($cm->getCollectionCapped());
     $this->assertEquals(1000, $cm->getCollectionMax());
     $this->assertEquals(500, $cm->getCollectionSize());
 }
 /**
  * Generates the code for the __sleep method for a proxy class.
  *
  * @param $class
  * @return string
  */
 private function generateSleep(ClassMetadata $class)
 {
     $sleepImpl = '';
     if ($class->reflClass->hasMethod('__sleep')) {
         $sleepImpl .= 'return parent::__sleep();';
     } else {
         $sleepImpl .= 'return array(';
         $first = true;
         foreach ($class->getReflectionProperties() as $name => $prop) {
             if ($first) {
                 $first = false;
             } else {
                 $sleepImpl .= ', ';
             }
             $sleepImpl .= "'" . $name . "'";
         }
         $sleepImpl .= ');';
     }
     return $sleepImpl;
 }