/** * Método que ejecuta un comando * @param command Comando a ejecutar * @param args Argumentos que se pasarán al comando * @return Resultado de la ejecución del comando * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl) * @version 2016-01-16 */ private static function dispatch($command, $args) { // Si el comando fue vacío se retorna estado de error if (empty($command)) { echo 'SowerPHP shell: debe indicar una orden a ejecutar', "\n"; return 1; } // Crear objeto $dot = strrpos($command, '.'); if ($dot) { $module = substr($command, 0, $dot); $command_real = substr($command, $dot + 1); $class = \sowerphp\core\App::findClass('Shell_Command_' . $command_real, $module); } else { $class = \sowerphp\core\App::findClass('Shell_Command_' . $command); } if (!class_exists($class)) { echo 'SowerPHP shell: ', $command, ': no se encontró la orden', "\n"; return 1; } $shell = new $class(); // poner modo verbose que corresponda (de 1 a 5) $argc = count($args); for ($i = 0; $i < $argc; $i++) { if (in_array($args[$i], ['-v', '-vv', '-vvv', '-vvvv', '-vvvvv'])) { $shell->verbose = strlen($args[$i]) - 1; unset($args[$i]); } } // Invocar main $method = new \ReflectionMethod($shell, 'main'); if (count($args) < $method->getNumberOfRequiredParameters()) { echo 'SowerPHP shell: ', $command, ': requiere al menos ', $method->getNumberOfRequiredParameters(), ' parámetro(s)', "\n"; echo ' Modo de uso: ', $command, ' '; foreach ($method->getParameters() as &$p) { echo $p->isOptional() ? '[' . $p->name . ']' : $p->name, ' '; } echo "\n"; return 1; } $return = $method->invokeArgs($shell, $args); // Retornar estado return $return ? $return : 0; }
// real en Configure::bootstrap()) ini_set('display_errors', true); error_reporting(E_ALL); // Definir el tiempo de inicio del script define('TIME_START', microtime(true)); // Definir directorio DIR_WEBSITE define('DIR_WEBSITE', DIR_PROJECT . '/website'); // Iniciar buffer ob_start(); // Incluir archivo de funciones básicas y clase para autoload include DIR_FRAMEWORK . '/lib/sowerphp/core/basics.php'; include DIR_FRAMEWORK . '/lib/sowerphp/core/App.php'; // Asociar el método que cargará las clases spl_autoload_register('\\sowerphp\\core\\App::loadClass'); // Crear capas de la aplicación (se registrarán extensiones) \sowerphp\core\App::createLayers($_EXTENSIONS); unset($_EXTENSIONS); // Definir si la aplicación se ejecuta en ambiente de desarrollo // Si estamos en Apache se debe definir en /etc/httpd/conf/httpd.conf: // SetEnv APPLICATION_ENV "dev". // Si estamos en una terminal se debe pasar el flas: --dev global $argv; if (isset($_SERVER['APPLICATION_ENV']) and $_SERVER['APPLICATION_ENV'] == 'dev') { define('ENVIRONMENT_DEV', true); } else { if (is_array($argv) and in_array('--dev', $argv)) { define('ENVIRONMENT_DEV', true); // se quita flasg --dev de los argumentos unset($argv[array_search('--dev', $argv)]); } }
/** * Método para renderizar una página * El como renderizará dependerá de la extensión de la página encontrada * @param page Ubicación relativa de la página * @param location Ubicación de la vista * @return Buffer de la página renderizada * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl) * @version 2014-12-18 */ public function render($page, $location = null) { // buscar página if ($location) { $location = self::location(\sowerphp\core\App::layer($location) . '/' . $location . '/View/' . $page); } else { $location = self::location($page, $this->request->params['module']); } // si no se encontró error if (!$location) { if ($this->request->params['controller'] == 'pages') { $this->render('/error/404'); } else { throw new Exception_View_Missing(array('view' => $page, 'controller' => Utility_Inflector::camelize($this->request->params['controller']), 'action' => $this->request->params['action'])); } return; } // preparar _header_extra (se hace antes de renderizar la página para // quitarlo de las variables por si existe if (isset($this->viewVars['_header_extra'])) { $_header_extra = ''; if (isset($this->viewVars['_header_extra']['css'])) { foreach ($this->viewVars['_header_extra']['css'] as &$css) { $_header_extra .= ' <link type="text/css" href="' . $this->request->base . $css . '" rel="stylesheet" />' . "\n"; } } if (isset($this->viewVars['_header_extra']['js'])) { foreach ($this->viewVars['_header_extra']['js'] as &$js) { $_header_extra .= ' <script type="text/javascript" src="' . $this->request->base . $js . '"></script>' . "\n"; } } unset($this->viewVars['_header_extra']); } else { $_header_extra = ''; } // dependiendo de la extensión de la página se renderiza $ext = substr($location, strrpos($location, '.') + 1); $class = App::findClass('View_Helper_Pages_' . ucfirst($ext)); $page_content = $class::render($location, $this->viewVars); if ($this->layout === null) { return $page_content; } // buscar archivo del tema que está seleccionado, si no existe // se utilizará el tema por defecto $layout = $this->getLayoutLocation($this->layout); if (!$layout) { $this->layout = $this->defaultLayout; $layout = $this->getLayoutLocation($this->layout); } // página que se está viendo if (!empty($this->request->request)) { $slash = strpos($this->request->request, '/', 1); $page = $slash === false ? $this->request->request : substr($this->request->request, 0, $slash); } else { $page = '/' . Configure::read('homepage'); } // determinar module breadcrumb $module_breadcrumb = []; if ($this->request->params['module']) { $modulos = explode('.', $this->request->params['module']); $url = ''; foreach ($modulos as &$m) { $link = Utility_Inflector::underscore($m); $module_breadcrumb[$link] = $m; $url .= '/' . $link; } $module_breadcrumb += explode('/', substr(str_replace($url, '', $this->request->request), 1)); } // determinar titulo $titulo_pagina = isset($this->viewVars['header_title']) ? $this->viewVars['header_title'] : $this->request->request; // renderizar layout de la página (con su contenido) return View_Helper_Pages_Php::render($layout, array_merge(array('_header_title' => Configure::read('page.header.title') . ($titulo_pagina ? ': ' . $titulo_pagina : ''), '_body_title' => Configure::read('page.body.title'), '_footer' => Configure::read('page.footer'), '_header_extra' => $_header_extra, '_page' => $page, '_nav_website' => Configure::read('nav.website'), '_nav_app' => Configure::read('nav.app'), '_timestamp' => date(Configure::read('time.format'), filemtime($location)), '_layout' => $this->layout, '_content' => $page_content, '_module_breadcrumb' => $module_breadcrumb), $this->viewVars)); }
</li> <?php } ?> </ul> <?php } ?> </div> </div> </div> <div class="container main-container"> <!-- BEGIN MAIN CONTENT --> <?php // menú de módulos si hay sesión iniciada if (\sowerphp\core\App::layerExists('sowerphp/app') and $_Auth->logged() and $_module_breadcrumb) { echo '<ol class="breadcrumb hidden-print">', "\n"; $url = '/'; foreach ($_module_breadcrumb as $link => &$name) { if (is_string($link)) { echo ' <li><a href="', $_base, $url, $link, '">', $name, '</a></li>', "\n"; $url .= $link . '/'; } else { echo ' <li class="active">', $name, '</li>'; } } echo '</ol>', "\n"; } // mensaje de sesión $message = \sowerphp\core\Model_Datasource_Session::message(); if ($message) {