コード例 #1
0
    /**
     * Creates definition object files based in the schema xml file
     *
     * @param TlalokesRegistry $reg
     */
    private static function buildDefsFromSchema(TlalokesRegistry &$reg)
    {
        // load schema xml file
        $schema = $reg->conf['path']['app'] . $reg->conf['path']['tmp'] . 'generator/schema.xml';
        $sx = simplexml_load_file($schema);
        // set response class string by table
        foreach ($sx->table as $table) {
            $table_name = (string) $table['name'];
            $r = '<?
/**
 * @DefinitionObject( table=\'' . $table_name . '\', build )
 */
class ' . tlalokes_str_change_format($table_name) . 'Def {
';
            // find column elements
            foreach ($table->children() as $key => $node) {
                // set response two array
                if ($key == 'column') {
                    $r2[(string) $node->name] = '';
                }
                // find foreign-key nodes and set it to an array (r2)
                if ($key == 'foreign-key') {
                    $f_tab = (string) $node['foreignTable'];
                    $f_col = (string) $node->reference['foreign'];
                    // on delete
                    $f_ond = isset($node['onDelete']) ? ', onDelete=\'' . strtolower((string) $node['onDelete']) . '\'' : '';
                    // on update
                    $f_onu = isset($node['onUpdate']) ? ', onUpdate=\'' . strtolower((string) $node['onUpdate']) . '\'' : '';
                    // reference_flag
                    $r2[(string) $node->reference['local']] = '
     * @ReferenceDef( table=\'' . $f_tab . '\', column=\'' . $f_col . '\'' . $f_ond . ' )';
                }
                // find index nodes and add it to a flag array (r3)
                if ($key == 'index') {
                    foreach ($node->children() as $index) {
                        $r3[(string) $index['name']] = true;
                    }
                }
                // find unique nodes and add it to a flag array (r4)
                if ($key == 'unique') {
                    foreach ($node->children() as $unique) {
                        $r4[(string) $unique['name']] = true;
                    }
                }
            }
            // set response property string by column
            foreach ($table->column as $column) {
                $col_name = (string) $column['name'];
                $col_type = ', type=\'' . strtolower((string) $column['type']) . '\'';
                $col_size = isset($column['size']) ? ', size=\'' . (string) $column['size'] . '\'' : '';
                $col_scal = isset($column['scale']) ? ', scale=\'' . (string) $column['scale'] . '\'' : '';
                $col_requ = isset($column['required']) ? ', required=\'true\'' : '';
                $col_auto = isset($column['autoIncrement']) ? ', autoIncrement=\'true\'' : '';
                $col_pkey = isset($column['primaryKey']) ? ', primaryKey=\'true\'' : '';
                $col_defa = isset($column['default']) ? ', default=\'' . $column['default'] . '\'' : '';
                $col_indx = isset($r3[$col_name]) ? ', index=\'true\'' : '';
                $col_uniq = isset($r4[$col_name]) ? ', unique=\'true\'' : '';
                $r .= '
    /**
     * @DefinitionObject( column=\'' . $col_name . '\'' . $col_type . $col_size . $col_requ . $col_auto . $col_pkey . $col_defa . $col_indx . $col_uniq . ' )';
                // if foreign-key exists for this column set response two in it
                if (isset($r2[$col_name])) {
                    $r .= $r2[$col_name];
                }
                // set php property name
                $r .= '
     */
    public $' . $col_name . ';
';
            }
            // close definition class string
            $r .= "\n}\n?>\n";
            // set definition file name
            $definition_file = $reg->conf['path']['app'] . $reg->conf['path']['def'] . tlalokes_str_change_format($table_name) . 'Def.php';
            // write file or send Exception
            if (!@file_put_contents($definition_file, $r)) {
                tlalokes_error_msg('Propel: Cannot write ' . $definition_file, true);
            }
        }
    }
コード例 #2
0
 /**
  * Parses URI and sets the request values
  *
  * @param string $query_string
  */
 private function parseUri($query_string)
 {
     $uri = explode('/', $query_string);
     // controller
     if (isset($uri[0])) {
         $class = tlalokes_str_change_format($uri[0]) . 'Ctl';
         if (!class_exists($class)) {
             tlalokes_error_msg('Controller do not exist');
         }
         $this->_controller = $class;
     }
     // action
     $count = count($uri);
     if ($count > 1) {
         // clear action
         $rx = '/^([a-zA-Z0-9_\\-]*).*/';
         if (isset($uri[1])) {
             $uri[1] = preg_replace($rx, '$1', $uri[1]);
         }
         if (isset($uri[2])) {
             $uri[2] = preg_replace($rx, '$1', $uri[2]);
         }
         unset($rx);
         // set action
         if (method_exists($class, $uri[1])) {
             $this->_action = $uri[1];
         } elseif (isset($uri[2]) && method_exists($class, $uri[2])) {
             $this->_action = $uri[2];
             $this->_id = tlalokes_core_get_type($uri[1]);
         } elseif (isset($uri[1])) {
             $this->_id = tlalokes_core_get_type($uri[1]);
         }
     }
     // set action according to REST
     if (!isset($this->_action) || !$this->_action) {
         // set PUT
         if (isset($_POST) && $_POST && (!isset($this->_id) || !$this->_id)) {
             $this->_action = 'create';
             // set POST
         } elseif (isset($_POST) && $_POST && isset($this->_id)) {
             $this->_action = 'update';
             // set GET
         } elseif ((!isset($_POST) || !$_POST) && (!isset($this->_id) || isset($this->_id))) {
             $this->_action = 'read';
         }
     } else {
         // set DELETE
         if (!isset($_POST) && !$_POST && isset($this->_id) && $this->_action == 'delete') {
             $this->_action = 'delete';
         }
     }
     // aditional vars
     if ($count == 4) {
         $uri = array_slice($uri, 2);
     } elseif ($count >= 5) {
         if (isset($this->_action) && $this->_action == $uri[1]) {
             $uri = array_slice($uri, 2);
         } else {
             $uri = array_slice($uri, 3);
         }
     }
     if ($count >= 4) {
         for ($i = 0; $i < $count; ++$i) {
             if (isset($uri[$i])) {
                 $array[$i] = $uri[$i] . '=' . $uri[++$i];
             }
         }
         parse_str(implode('&', $array), $uri);
         // set new vars
         foreach ($uri as $key => $value) {
             if ($value) {
                 $this->{$key} = $value;
             }
         }
     }
 }
コード例 #3
0
  public function filter ()
  {
    \$response = {$name}Bss::filter( \$this->request );
    if ( is_array( \$response ) ) {
      \$this->response->vars = \$_SERVER['QUERY_STRING'];
      \$this->response->pager = \$response['pager'];
      \$this->response->list = \$response['data'];

DOT;

// looks for references
$ref = '';
$spc = "      ";
foreach ( $columns as $key => $column ) {
  if ( isset( $column->reference ) && $column->reference ) {
    $mod_key = tlalokes_str_change_format( $column->reference->table );
    $ref .= "$spc// get reference's content for {$column->reference->table}\n".
            "$spc\${$column->reference->table} = {$mod_key}Bss::getAll( \$this->request );\n".
            "$spc\$this->response->{$column->reference->table} = \${$column->reference->table}['data'];\n";
    unset( $mod_key );
  }
}
unset( $spc );

$str .= $ref . <<<DOT
    } else {
      \$this->response->exception = \$response;
      \$list = {$name}Bss::getAll( \$this->request );
      \$this->response->list = \$list['pager'];
      \$this->response->data = \$list['data'];
    }