Пример #1
0
 /**
  * Método llamado automáticamente para generar la ayuda.
  */
 public function help()
 {
     // Obtenemos el nombre de comando.
     $command = strtolower(array_pop(explode('_', $this->class)));
     $script = $_SERVER['PHP_SELF'];
     Shell_Cli::write_line($this->descripcion);
     if (is_array($this->lines) && count($this->lines) > 0) {
         Shell_Cli::write_line('Usage: ');
         foreach ($this->lines as $line) {
             Shell_Cli::write_line("  php {$script} {$command} {$line}");
         }
     } else {
         Shell_Cli::write_line("Usage: php {$script} {$command}");
     }
     Shell_Cli::write_line('');
     Shell_Cli::write_line($this->help);
     exit;
 }
Пример #2
0
 /**
  * Despachamos una petición.
  */
 public static function dispatch()
 {
     // Obtenemos los parametros.
     $params = Shell_Cli::parse_args($_SERVER['argv']);
     // Obtenemos el controlador.
     if (!isset($params[0]) || $params[0] == 'help') {
         // Usamos de ayuda.
         $controller = 'Shell_Controller_Ayuda';
     } else {
         // Armamos el nombre.
         $c_name = ucfirst(strtolower($params[0]));
         $c_name = preg_replace('/\\s/', '_', $c_name);
         if (!class_exists('Shell_Controller_' . $c_name)) {
             Shell_Cli::write_line(Shell_Cli::get_colored_string("Parámetros incorrectos, intente llamando a la ayuda con --help", 'red'));
             exit;
         } else {
             $controller = 'Shell_Controller_' . $c_name;
         }
     }
     $c = new $controller($params);
     $c->start();
 }
Пример #3
0
 /**
  * Obtenemos el código PHP del archivo a parsear.
  * @param string $file Nombre del archivo.
  * @param string $class Clase a extender.
  * @param string $subpackage Subpaquete del bloque phpdoc.
  * @param string $alias Alias de la clase.
  * @return bool Resultado de la ejecución.
  */
 protected function make_template($file, $class, $subpackage, $alias)
 {
     $t = "<?php\n/**\n * {{FILE}} is part of Marifa.\n *\n * Marifa is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * Marifa is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with Marifa. If not, see <http://www.gnu.org/licenses/>.\n *\n * @license     http://www.gnu.org/licenses/gpl-3.0-standalone.html GNU Public License\n * @filesource\n * @package\t\tMarifa\\Base{{SUBPACKAGE1}}\n */\ndefined('APP_BASE') || die('No direct access allowed.');\n\n/**\n * Alias de {{BASE_CLASS_NAME}}\n *\n * @package    Marifa\\Marifa{{SUBPACKAGE2}}\n */\n{{DECLARACION}}";
     $t = str_replace('{{DECLARACION}}', $class, $t);
     $t = str_replace('{{BASE_CLASS_NAME}}', $alias, $t);
     $t = str_replace('{{SUBPACKAGE1}}', trim($subpackage) == '' ? '' : "\n * @subpackage  {$subpackage}", $t);
     $t = str_replace('{{SUBPACKAGE2}}', trim($subpackage) == '' ? '' : "\n * @subpackage {$subpackage}", $t);
     $t = str_replace('{{FILE}}', basename($file), $t);
     // Creamos el path.
     $base_dir = dirname($file);
     if (!file_exists($base_dir)) {
         mkdir($base_dir, 0777, TRUE);
     }
     if (!file_exists($file)) {
         if (!file_put_contents($file, $t)) {
             Shell_Cli::write_line(Shell_Cli::get_colored_string("ERROR: {$file}", 'red'));
             return FALSE;
         }
     }
     return TRUE;
 }
Пример #4
0
 /**
  * Método donde inicia el procesamiento del controlador.
  */
 public function start()
 {
     // Imprimimos la versión del software.
     Shell_Cli::write_line(sprintf('CLI de utilidades de Marifa. Versión: %s.', VERSION));
     // Verificamos si necesitamos la ayuda de un comando.
     if (isset($this->params[0]) && isset($this->params[1]) && $this->params[0] == 'help') {
         // Obtenemos la clase.
         $class = 'Shell_Controller_' . ucfirst(strtolower($this->params[1]));
         if (!class_exists($class)) {
             Shell_Cli::write_line('Comando inválido');
             return;
         }
         $c = new $class($this->params);
         $c->help();
         return;
     }
     // Imprimimos resumen.
     Shell_Cli::write_line("Uso: php {$_SERVER['PHP_SELF']} <comando> [<argumentos>] [--help]");
     Shell_Cli::write_line('');
     Shell_Cli::write_line('Listado de comandos:');
     // Cargamos la lista de controladores.
     $c_list = scandir(dirname(__FILE__));
     // Inicializamos la lista de comandos.
     $command_list = array();
     foreach ($c_list as $cl) {
         if ($cl == '.' || $cl == '..' || $cl == 'ayuda.php' || !is_file(dirname(__FILE__) . '/' . $cl)) {
             continue;
         }
         // Obtenemos la información del path.
         $pi = pathinfo(dirname(__FILE__) . '/' . $cl);
         // Verificamos exista filename (PHP > 5.2.0)
         if (!isset($pi['filename'])) {
             $pi['filename'] = substr($pi['basename'], 0, strlen($pi['extension']) + 1);
         }
         // Generamos el nombre de la clase.
         $class_name = 'Shell_Controller_' . ucfirst($pi['filename']);
         // Verificamos que exista la clase.
         if (!class_exists($class_name)) {
             continue;
         }
         // Hacemos reflection de la clase.
         $r_c = new ReflectionClass($class_name);
         // Obtenemos el nombre de la clase padre.
         $r_p = $r_c->getParentClass();
         // Verificamos el padre sea Controller.
         if (!is_object($r_p) || $r_p->getName() !== 'Shell_Controller') {
             continue;
         }
         unset($r_p);
         $obj = new stdClass();
         $d_p = $r_c->getDefaultProperties();
         // Obtenemos las propiedades importantes.
         if (isset($d_p['descripcion'])) {
             // Dejamos solo el primer párrafo.
             $obj->descripcion = $d_p['descripcion'];
         } else {
             $obj->descripcion = NULL;
         }
         // Seteamos el nombre de llamada.
         $obj->name = strtolower($pi['filename']);
         // Agregamos el comando a la lista de comandos.
         $command_list[] = $obj;
     }
     // Imprimimos la lista de comandos.
     foreach ($command_list as $c) {
         Shell_Cli::write_line(sprintf('  %-15.13s%s', $c->name, $c->descripcion));
     }
     // Imprimimos pie de página.
     Shell_Cli::write_line("\nVea php {$_SERVER['PHP_SELF']} help <command> o php {$_SERVER['PHP_SELF']} <command> --help para más información sobre el comando.");
 }
Пример #5
0
 /**
  * Verificamos el estado de configuración de la base de datos.
  */
 protected static function check_db_status()
 {
     // Verificamos coneccion a la base de datos.
     try {
         $db = Database::get_instance();
     } catch (Database_Exception $e) {
         Shell_Cli::write_line(Shell_Cli::get_colored_string('Error ', 'red') . $e->getCode() . ': ' . $e->getMessage());
     }
     Shell_Cli::write_line('Conección DB: ' . Shell_Cli::get_colored_string('OK', 'green'));
     // Intentamos crear la tabla de migraciones.
     try {
         $db->insert('CREATE TABLE IF NOT EXISTS `migraciones` ( `numero` INTEGER NOT NULL, `fecha` DATETIME NOT NULL, PRIMARY KEY (`numero`) );');
     } catch (Database_Exception $e) {
         Shell_Cli::write_line(Shell_Cli::get_colored_string('Error ', 'red') . $e->getCode() . ': ' . $e->getMessage());
     }
 }