Example #1
0
 public function create(Skt_Core_Request $req)
 {
     $name = $req->getParam('vld', FALSE);
     if (!$name) {
         Skt_Core_Prompt::print_('O nome passado esta invalido', Skt_Core_Prompt::ERROR);
     } else {
         $dir = $this->_dir_app . $this->_configure->path;
         $this->_file->include_tpl('validator', $dir, array('vld' => ucfirst(strtolower($name))), "inc_" . strtolower($name));
     }
 }
Example #2
0
 public function create(Skt_Core_Request $req)
 {
     $req->getParam('repository_app', 'ibe-apps');
     $this->_directory->create($this->_dir_app);
     foreach ($this->_configure->paths as $path) {
         $this->_directory->create($this->_dir_app . $path);
     }
     $vars = $req->getParamsWithDefaults($this->_configure->index);
     $this->_file->include_tpl("index", $this->_dir_app, $vars);
     $this->_file->include_tpl("inc_configure", $this->_dir_app . "_modules");
     $this->_file->include_tpl("inc_views", $this->_dir_app . "_modules");
 }
Example #3
0
 public static function run($argv)
 {
     $req = new Skt_Core_Request($argv);
     if ($req->getMaker()) {
         $mk_class = implode("_", array_map("ucfirst", explode("_", strtolower($req->getMaker()))));
         $_directory = new Skt_Core_Directory();
         $_file = new Skt_Core_File($req->getMaker());
         $maker = new $mk_class($_directory, $_file);
         $maker->dispatch($req);
         Skt_Core_Prompt::responseIfHttp();
     }
 }
Example #4
0
 public function create(Skt_Core_Request $req)
 {
     try {
         ob_start();
         // inserindo a biblioteca doctrine
         $dir = $this->_dir_app . $this->_configure->path_doctrine_library;
         if (!is_dir($dir)) {
             Skt_Core_Prompt::print_($dir, Skt_Core_Prompt::ERROR);
             $this->copy_directory('_makers/doct/tpls/Doctrine-1.2.4/', $dir);
             $this->_file->include_tpl("inc_doctrine", $this->_dir_app . '_extensions');
         }
         // criando diretorios para o doctrine models, base, schemas
         foreach ($this->_configure->doctrine_configure as $directory) {
             $this->_directory->create($this->_dir_app . $directory);
         }
         // configurando o nome das pastas para o gerador de codigos
         $confs = array();
         foreach ($this->_configure->doctrine_configure as $conf_name => $conf_value) {
             $confs[$conf_name] = $this->_dir_app . $conf_value;
         }
         // conectando o doctrine ao banco de dados atraves do dns em configuracao.php
         require_once $this->_dir_app . '_maps/doctrine/Doctrine.php';
         spl_autoload_register(array('Doctrine', 'autoload'));
         if (!Doctrine_Manager::connection($this->_configure->doctrine_database_dns)) {
             throw new Exception('Not possible connect in database');
         }
         // executando os comandos doctrine
         $cli = new Doctrine_Cli($confs);
         $params = array_merge(array('doctrine'), explode('.', $req->getParam('command')));
         $cli->run($params);
         // capturando saida do doctrine para enviar como json
         $out = ob_get_contents();
         ob_end_clean();
         // inserindo a saida no json
         if (isset($out) && !empty($out)) {
             Skt_Core_Prompt::print_($out, Skt_Core_Prompt::ALERT);
         }
     } catch (Exception $e) {
         Skt_Core_Prompt::print_($e->getMessage(), Skt_Core_Prompt::ERROR);
     }
 }
 public function __construct($argv)
 {
     $this->params = array();
     if (!isset($_SERVER['SHELL'])) {
         Skt_Core_Request::$request_http = TRUE;
         $url = explode('/', rtrim($_SERVER['REQUEST_URI'], " \t\n\r/"));
         $exit = false;
         $index = array_search('ibe.php', $url);
         if ($index) {
             $slices = array_slice($url, 0, $index);
         } else {
             array_pop($url);
             $slices = $url;
         }
         if ($index) {
             $url = array_slice($url, ++$index, sizeof($url));
             $size = sizeof($url);
             switch ($size) {
                 case 0:
                     break;
                 case 1:
                     $this->maker = $url[0];
                     break;
                 default:
                     $this->maker = array_shift($url);
                     $size = sizeof($url);
                     for ($i = 0; $i < $size; $i++) {
                         $j = $i;
                         $_GET[$url[$i]] = isset($url[$i++]) ? $url[$i] : null;
                         $_REQUEST[$url[$j]] = $_GET[$url[$j]];
                     }
                     break;
             }
         }
         $this->params = $_REQUEST;
     } else {
         $size = sizeof($argv);
         if ($size > 1) {
             $this->maker = $argv[1];
             for ($i = 2; $i < $size; $i++) {
                 $param = explode(":", $argv[$i]);
                 $this->params[$param[0]] = $param[1];
             }
         }
     }
 }
Example #6
0
 public function create(Skt_Core_Request $req)
 {
     $this->_directory->create($this->_dir_app . $this->_configure->base);
     $vars = $req->getParamsWithDefaults($this->_configure->database);
     $host = $vars['host'];
     $user = $vars['user'];
     $pass = $vars['pass'];
     $schema = $vars['schm'];
     @($conn = mysql_connect($host, $user, $pass));
     if ($conn) {
         $sch = mysql_select_db($schema);
         if (!$sch) {
             Skt_Core_Prompt::print_('not select schema', Skt_Core_Prompt::ERROR);
             return;
         }
         $show_tables = 'SHOW TABLES';
         $table = array();
         $result = mysql_query($show_tables);
         if ($result) {
             while (@($row = mysql_fetch_array($result))) {
                 //Tabelas
                 $table[$row[0]] = array();
                 Skt_Core_Prompt::print_("lendo tabela " . $row[0]);
                 //Configuracao das colunas
                 $result_show_table = mysql_query('DESC ' . $row[0]);
                 while ($result_show_table && ($row_tbl = mysql_fetch_array($result_show_table))) {
                     $table[$row[0]]['field'][$row_tbl['Field']] = $this->getType($row_tbl['Type']);
                 }
                 //Configurando chaves
                 $result_show_keys = mysql_query('SHOW KEYS FROM ' . $row[0]);
                 while ($result_show_keys && ($row_tbl = mysql_fetch_array($result_show_keys))) {
                     if ($row_tbl['Key_name'] == 'PRIMARY') {
                         $table[$row[0]]['primary_key'][] = $row_tbl['Column_name'];
                     } else {
                         $foreign_table = explode('_', $row_tbl['Column_name']);
                         $foreign_table[sizeof($foreign_table) - 1] = "";
                         $table[$row[0]]['foreign_key'][$row_tbl['Column_name']] = implode("", array_map("ucfirst", array_map("strtolower", $foreign_table)));
                         // ucfirst(strtolower(implode('',$foreign_table)));
                     }
                 }
             }
         } else {
             Skt_Core_Prompt::print_(mysql_error(), Skt_Core_Prompt::ERROR);
         }
         foreach ($table as $tbl_name => $tbl_confs) {
             $class = explode('_', $tbl_name);
             $name = '';
             foreach ($class as $n) {
                 $name .= ucfirst(strtolower($n));
             }
             /// Comentario inicial
             $file_php = "<?php\n\n";
             $file_php .= "/**\n";
             $file_php .= " * Mapeamento Objeto Relacional \n *\n";
             //Configurando os metodos campos
             if (isset($tbl_confs['field'])) {
                 foreach ($tbl_confs['field'] as $f_name => $f_type) {
                     $file_php .= " * @method " . ucfirst(strtolower($name)) . "Map set" . ucfirst(strtolower($f_name)) . "(\$value) metodo set\n";
                     $file_php .= " * @method " . ucfirst(strtolower($name)) . "Map get" . ucfirst(strtolower($f_name)) . "() metodo get\n";
                 }
             }
             $file_php .= " * @date " . date('d/m/Y') . "\n";
             $file_php .= " * @autor Renan Henrique Abreu<*****@*****.**> SKT\n";
             $file_php .= " */\n";
             /// Criacao da classe
             $file_php .= "class " . $name . "Table extends Ibe_Map{\n\n";
             $file_php .= "\tprotected function configure(){\n";
             $file_php .= "\t\t\$this->table_name  = '" . $schema . "." . $tbl_name . "';\n";
             $file_php .= "\t\t\$this->primary_key = '" . $tbl_confs['primary_key'][0] . "';\n";
             /// Configurando chave estrangeira
             if (isset($tbl_confs['foreign_key'])) {
                 $file_php .= "\t\t\$this->foreign_key = array(";
                 $fks = array();
                 foreach ($tbl_confs['foreign_key'] as $fk_name => $fk_table) {
                     $fks[] = "\n\t\t\t'" . $fk_name . "'=>'" . $fk_table . "'";
                 }
                 $file_php .= implode(',', $fks);
                 $file_php .= "\n\t\t);\n";
             }
             //Configurando campos
             if (isset($tbl_confs['field'])) {
                 $file_php .= "\t\t\$this->columns_conf = array(";
                 $f = array();
                 foreach ($tbl_confs['field'] as $f_name => $f_type) {
                     $f[] = "\n\t\t\t'" . $f_name . "'=>'" . $f_type . "'";
                 }
                 $file_php .= implode(',', $f);
                 $file_php .= "\n\t\t);\n";
             }
             //Fechando funcao configure
             $file_php .= "\t}\n\n\n";
             //Fechando classe
             $file_php .= '}';
             //Criando o arquivo
             $dir = $this->_dir_app . "_maps" . DS . "tables" . DS;
             if (is_dir($dir)) {
                 file_put_contents($dir . 'tbl_' . strtolower($name) . '.php', $file_php);
                 $map = "_maps" . DS . 'inc_' . strtolower($name) . '.php';
                 if (!file_exists($this->_dir_app . $map)) {
                     $include = "_maps" . DS . "tables" . DS;
                     $file_php = "<?php\n\n";
                     $file_php .= "include_once('" . $include . 'tbl_' . strtolower($name) . '.php' . "');\n\n\n";
                     $file_php .= "/**\n";
                     $file_php .= " * Classe de regras de negocio \n *\n";
                     $file_php .= " * @date " . date('d/m/Y') . "\n";
                     $file_php .= " * @autor Renan Henrique Abreu<*****@*****.**> SKT\n";
                     $file_php .= " */\n";
                     $file_php .= "class " . $name . "Map extends " . $name . "Table {\n\n\n}";
                     file_put_contents($this->_dir_app . $map, $file_php);
                 }
                 Skt_Core_Prompt::print_("map " . ucfirst(strtolower($name)) . " criado com sucesso");
             } else {
                 Skt_Core_Prompt::print_("application not exists", Skt_Core_Prompt::ERROR);
             }
         }
         mysql_close();
     } else {
         Skt_Core_Prompt::print_("not permition", Skt_Core_Prompt::ERROR);
     }
 }