Esempio n. 1
0
 public function testJSON()
 {
     $attribute = DataMapper\Type::normalizeAttribute(array('type' => 'json'));
     $type = $this->getType('json');
     $this->assertInstanceOf('\\Owl\\DataMapper\\Type\\JSON', $type);
     $this->assertInstanceOf('\\Owl\\DataMapper\\Type\\Mixed', $type);
     $json = array('foo' => 'bar');
     $this->assertEquals($json, $type->normalize($json, array()));
     $this->assertEquals($json, $type->normalize(json_encode($json), array()));
     $this->assertNull($type->store(array(), array()));
     $this->assertEquals(json_encode($json), $type->store($json, array()));
     $this->setExpectedException('\\UnexpectedValueException');
     $type->restore('{"a"', array());
     $this->assertSame(array(), $type->getDefaultValue(array()));
     $this->assertSame(array(), $type->getDefaultValue(array('allow_null' => true)));
 }
Esempio n. 2
0
 /**
  * 格式化从Data class获得的配置信息
  *
  * @param array $options
  * @return array
  */
 protected function normalizeOptions(array $options)
 {
     $options = array_merge(['service' => null, 'collection' => null, 'attributes' => [], 'readonly' => false, 'strict' => false], $options);
     $primary_key = [];
     foreach ($options['attributes'] as $key => $attribute) {
         $attribute = Type::normalizeAttribute($attribute);
         if ($attribute['strict'] === null) {
             $attribute['strict'] = $options['strict'];
         }
         if ($attribute['primary_key'] && !$attribute['deprecated']) {
             $primary_key[] = $key;
         }
         $options['attributes'][$key] = $attribute;
     }
     if (!$primary_key) {
         throw new \RuntimeException('Mapper: undefined primary key');
     }
     $options['primary_key'] = $primary_key;
     return $options;
 }