Exemplo n.º 1
0
 /**
  * Constructor
  * Inicializa las dependencias de la API
  *
  * @return true
  * ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
  * @author Luis Gdonis <*****@*****.**>
  * @since  3.0.0 alpha
  */
 public function start()
 {
     // * Metodos disponibles
     $methods = $this->_methods;
     // * Crea informacion de controlador
     $params = $_SERVER['argv'];
     // * Metodo solicitado
     $method = isset($params[1]) ? $params[1] : 'help';
     // * Limpia vector de parametros
     unset($params[0]);
     //Nombre de archivo
     unset($params[1]);
     //Metodo solicitado
     $params = array_filter(array_values($params));
     // * Obtengo la cantidad de parametros recibidos
     $paramc = count($params);
     // * Verifica si existe el metodo solicitado en la lista de metodos disponibles
     if (!array_key_exists($method, $this->_methods)) {
         Console::response('Metodo no valido', 3);
         return;
     }
     /*
      * El metodo help unicamente desplegara
      * una lista de metodos disponibles y los parametros
      * solicitados para ejecutar cada metodo en la consola
      */
     if ($method == 'help') {
         Console::response('Available methods:');
         Console::response(null, 5);
         foreach ($methods as $index => $value) {
             Console::response(array($index => $value['desc']));
         }
         return;
     }
     // * Obtiene informacion del metodo de consola
     $methods = $methods[$method];
     // * Incluye el archivo del metodo
     include 'Core' . DS . $methods['file'];
     // * Da formato correcto a nombre de metodo
     $method = explode('-', $method);
     // * camelCase format
     $method_name = $method[0] . ucfirst($method[1]);
     if (isset($method[2])) {
         $method_name .= ucfirst($method[2]);
     }
     // Coloca el nombre del metodo en la primera posicion del vector
     array_unshift($params, 'cli', $method_name);
     // * Invoca al metodo
     $lesli_cli = new $methods['class']($params);
 }
Exemplo n.º 2
0
 /**
  * New secttion
  * Crea la estructura de una nueva seccion
  *
  * @return true
  * ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
  * @author Luis Gdonis <*****@*****.**>
  * @since  2.0.0.0-alpha
  */
 private function _newSection()
 {
     $controller = $this->_controller;
     /*
      * Sitio web
      */
     $site = $controller[2];
     /*
      * Seccion
      */
     $section = $controller[3];
     /*
      * Ruta de sitio web
      */
     $website_path = 'www' . DS . $site;
     /*
      * Tipo de seccion
      */
     $section_type = $section;
     /*
      * Cambia tipo de seccion
      */
     if ($section != 'Config' && $section != 'Template') {
         /*
          * Directorio corresponde a seccion
          */
         $section_type = 'section';
     }
     /*
      * Estructura de directorios
      */
     $folders = array('Config' => array(), 'Template' => array('css', 'html', 'locale'), 'section' => array('css', 'html', 'locale', 'img'));
     /*
      * Ruta de la nueva seccion
      */
     $section_path = $website_path . '/' . $section;
     /*
      * Crea el folder de la seccion
      */
     mkdir($section_path);
     Console::response('Directorio ' . $section_path);
     if ($section == 'Config') {
         /*
          * Archivo de configuracion
          */
         $file = $section_path . DS . 'config.php';
         $text = "<?php\n";
         /*
          * Informacion de sitio web
          */
         $text .= "/*\n * Website info \n */\n";
         $text .= "Configure::write('info', array( \n";
         $text .= "    'name' => '" . $site . "', \n";
         $text .= "    'description' => 'My amazing website', \n";
         $text .= "    'version' => '1.0.0', \n";
         $text .= "    'env' => 'dev' \n)); \n \n";
         /*
          * Plantillas
          */
         $text .= "/*\n * Plantillas \n */\n";
         $text .= "Configure::write('template', array( \n";
         $text .= "    'default' => 'default', \n)); \n \n";
         /*
          * Variables
          */
         $text .= "/*\n * Variables \n */\n";
         $text .= "Configure::write('vars', array( \n";
         $text .= "    'apiUrl' => 'http://domain.com/api', \n)); \n \n";
         /*
          * Helpers
          */
         $text .= "/*\n * Helpers \n */\n";
         $text .= "Configure::write('helpers', array('html', 'seo'));";
         /*
          * Crea el archivo,
          * envia estado a pantalla
          */
         $this->_file($file, $text);
         Console::response('Archivo ' . $file);
         /*
          * Archivo de rutas
          */
         $file = $section_path . DS . 'routes.php';
         $text = "<?php\n";
         $text .= "/*\n * Rutas \n */\n";
         $text .= "router::connect('default','home');";
         /*
          * Crea el archivo,
          * envia estado a pantalla
          */
         $this->_file($file, $text);
         Console::response('Archivo ' . $file);
     }
     /*
      * Crea directorios basicos por tipo de seccion
      */
     foreach ($folders[$section_type] as $folder) {
         $sub_folder = $section_path . '/' . $folder;
         mkdir($sub_folder);
         Console::response('Directorio ' . $sub_folder);
         /*
          * Archivos de plantilla
          */
         if ($section == 'Template' && $folder == 'html') {
             $file = $sub_folder . '/default.php';
             $text = "<!Doctype html>\n";
             $text .= "<html>\n<head>\n<meta charset='UTF8'>\n";
             $text .= "<title>Lesli - PHP FrontController</title>\n</head>";
             $text .= "<body>\n<h3>Sitio web creado de forma existosa!!</h3>\n";
             $text .= "<?php\n " . 'include $content;' . "\n?>\n</body>\n</html>";
             $this->_file($file, $text);
             Console::response('Archivo ' . $file);
         }
         /*
          * Archivos de seccion
          */
         if ($section_type == 'section' && $folder == 'html') {
             $file = $sub_folder . DS . $section . '.php';
             $text = "<section id='{$section}'>\n";
             $text .= "<article>\n<p>nueva seccion</p>\n</article>\n</section>";
             $this->_file($file, $text);
             Console::response('Archivo ' . $file);
         }
     }
     Console::response(null, 5);
 }