コード例 #1
0
ファイル: core_types.php プロジェクト: rentalhost/core
 public static function type_return($conn, $type, $data, $optional = null, $nullable = null, $method = 'set')
 {
     self::$_conn = $conn;
     // Obtém os dados do tipo
     $type = isset(self::$_types[$type]) ? self::$_types[$type] : self::_load_type($type);
     // Se for opcional e o valor estiver vazio
     if ($data === null) {
         if ($method === 'get') {
             if ($optional === null || $type['optional'] === null) {
                 //TODO: se não for opcional para o valor ou para o tipo, informa um erro
                 return null;
             }
         } else {
             // Em outro caso, retorna o valor opcional
             return $nullable !== true ? $type['optional'] : 'NULL';
         }
     }
     // Se tudo acontecer normalmente, define o método que será usado
     $call_method = ($type['method'] === true ? 'both' : $method) . '_' . $type['alias'];
     $call_method = array($type['object'], $call_method);
     // Se a informação foi instancia de um core_model_row, obtém apenas o ID
     if ($data instanceof core_model_row) {
         $data = $data->id;
     }
     // Se for chamável
     if (is_callable($call_method)) {
         return call_user_func($call_method, $data);
     }
     // Em outro caso, retorna o próprio valor
     return $method === 'get' ? $data : 'NULL';
 }
コード例 #2
0
ファイル: core_model_row.php プロジェクト: rentalhost/core
 private function _get_typed_value($key, $direction = 'get')
 {
     $data = $this->_data[$key];
     // Tipo de saída
     $type_data = isset($data['type']) ? $data['type'] : array('default', null, true);
     $type_data[0] = $type_data[0] ? $type_data[0] : 'default';
     // Retorna o valor tipado
     return core_types::type_return($this->_conn, $type_data[0], $data['internal'], $type_data[1], $type_data[2], $direction);
 }
コード例 #3
0
ファイル: core_model_query.php プロジェクト: rentalhost/core
 public static function query($conn, $query, $from = null, $args = null, $row = null)
 {
     $query = self::parse_query($query);
     $query_string = null;
     foreach ($query as $data) {
         // Se for uma string, apenas copia
         if (is_string($data)) {
             $query_string .= $data;
             continue;
         }
         switch ($data['object']) {
             // Se for um object this
             case 'this':
                 $query_string .= '`' . $conn->escape($from->table()) . '`';
                 continue 2;
                 // Se for uma variável
             // Se for uma variável
             case 'variable':
                 // Define a informação que será passada
                 // Se for uma variável do objeto [@this.id]...
                 // Em casos comuns, usa o argumento informado
                 $variable_data = isset($data['this']) ? $row->__get($data['name']) : @(ctype_digit($data['name']) ? $args[$data['name'] - 1] : $args[$data['name']]);
                 $data_type = isset($data['type']) ? $data['type'] : 'string';
                 $query_string .= core_types::type_return($conn, $data_type, $variable_data, @$data['optional'], @$data['null']);
                 continue 2;
         }
     }
     return $query_string;
 }