Exemplo n.º 1
0
 protected function getType($name)
 {
     return DataMapper\Type::getInstance()->get($name);
 }
Exemplo n.º 2
0
 /**
  * 把存储服务内获取的数据,打包成Data实例
  *
  * @param array $record
  * @param Data [$data]
  * @return Data
  */
 public function pack(array $record, Data $data = null)
 {
     $types = Type::getInstance();
     $values = [];
     $attributes = $this->getAttributes();
     foreach ($record as $key => $value) {
         if (!isset($attributes[$key])) {
             continue;
         }
         $attribute = $attributes[$key];
         $values[$key] = $types->get($attribute['type'])->restore($value, $attribute);
     }
     if ($data) {
         $data->__pack($values, false);
     } else {
         $class = $this->class;
         $data = new $class(null, ['fresh' => false]);
         $data->__pack($values, true);
     }
     return $data;
 }