Exemplo n.º 1
0
 /**
  * 
  */
 protected function setup()
 {
     if (empty($this->entity_class)) {
         $this->entity_class = DB::option('collection_class');
     }
     return $this->classname($this->entity_class)->table('union_result')->union_setup();
 }
Exemplo n.º 2
0
 /**
  * Вызывается в DB.Connection после соединения
  */
 public function after_connect()
 {
     $this->pdo->exec('SET NAMES ' . DB::option('charset'));
     $time_zone = DB::option('time_zone');
     if ($time_zone !== false) {
         $this->pdo->exec("SET time_zone = {$time_zone}");
     }
 }
Exemplo n.º 3
0
Arquivo: ORM.php Projeto: techart/tao
 /**
  * Создает объект сущности класса, имя которого указано в опции classname
  *
  * @return mixed
  */
 public function make_entity()
 {
     $args = func_get_args();
     switch (count($args)) {
         case 0:
             $args = array(array(), $this->clear());
             break;
         default:
             $args[] = $this->clear();
             break;
     }
     $entity = isset($this->options['classname']) ? Core::amake($this->options['classname'], $args) : Core::make(DB::option('collection_class'));
     if (method_exists($entity, 'defaults')) {
         $entity->defaults($this->options['defaults']);
     } else {
         $array_access = $entity instanceof ArrayAccess;
         foreach ($this->options['defaults'] as $k => $v) {
             if ($array_access && !isset($entity[$k])) {
                 $entity[$k] = $v;
             } else {
                 if (!isset($entity->{$k})) {
                     $entity->{$k} = $v;
                 }
             }
         }
     }
     //$entity->mapper = $this->clear();
     $entity->after_make();
     return $entity;
 }
Exemplo n.º 4
0
Arquivo: DB.php Projeto: techart/tao
 /**
  * Возвращает объект строки результата
  *
  * Обрабатывает строку результата и возвращает построенный на её основе объект
  *
  * @params array $row массив, соответствующий записи
  *
  * @return object
  */
 protected function make_row_instance(array $row)
 {
     if ($this->prototype) {
         $class_field = DB::option('row_class_field');
         $prototype = isset($row[$class_field]) && !$this->ignore_type && Core_Types::is_subclass_of($this->prototype, $type = $row[$class_field]) ? new $type() : $this->prototype;
         $array_access = $prototype instanceof ArrayAccess;
         $result = clone $prototype;
         foreach ($row as $k => $v) {
             $v = $this->adapter->cast_column($this->metadata[$k], $v);
             $array_access ? $result[$k] = $v : ($result->{$k} = $v);
         }
         return $result;
     } else {
         foreach ($row as $k => &$v) {
             $v = $this->adapter->cast_column($this->metadata[$k], $v);
         }
         return $row;
     }
 }