Exemple #1
0
 * Copyright 2015 Bill.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
$router = new Lib\Router();
$router->respond('get', '/', 'user')->respond('get', '/home/index', 'home', 'index')->respond('get', 'home/index/(.*)', 'home', 'other')->respond('get|post', 'blog(/\\d{4}(/\\d{2}(/\\d{2}(/[a-z0-9_-]+)?)?)?)?', 'blog1')->respond('get|post', 'blog(/\\d{4}(/\\d{2}(/\\d{2}(.*)?)?)?)?', 'blog2')->respond('get|post', '/user/(\\d+)/(\\w+)', 'usuarioIdNome', 'index')->respond('get|post', '/user/(\\d+)', 'usuarioId', 'index')->respond('get|post', '/user/(\\d+)/(\\w+)/(\\w+)', 'usuarioIdNomeESobrenome', 'index')->respond('get|post', '/user/(\\d+)/(.*)', 'usuarioIdNomeCompleto', 'index')->respond('get|post', '/user', 'user', 'index')->respond('post', 'msg', 'msg')->respond('post', 'sendmail/(.*[^<>()[\\]\\.,;:\\s@\\"])@(.*[^<>()[\\]\\.,;:\\s@\\"])\\.(\\w+)/(.*)', 'sendmail')->respond('post', 'upfile', 'upfile')->respond('get|post', 'controller/(.*?)/(.*?)/(.*)', function ($controller, $action, $params) {
    echo 'Controller: ' . $controller . '<br>Action: ' . $action . '<br>Params: ' . $params;
    //after process, call controller/action
    return ['controller' => $controller, 'action' => $action, 'params' => 'none'];
})->respond('get|post', 'blogs(/\\d{4}(/\\d{2}(/\\d{2}(/[a-z0-9_-]+)?)?)?)?', function ($ano, $mes, $dia, $titulo) {
    echo 'Ano: ' . $ano . '<br>Mês: ' . $mes . '<br>Dia: ' . $dia . '<br>Título: ' . $titulo;
    exit('<br>finish callback!');
    //In this case, the CALLBACK call the Controller/Action or stop...
});
//Resolve with callback
define('BACKUP_DIR', realpath(__DIR__ . '/app/backup') . DIRECTORY_SEPARATOR);
define('CONTROLLERS_DIR', realpath(__DIR__ . '/app/controllers') . DIRECTORY_SEPARATOR);
define('MODELS_DIR', realpath(__DIR__ . '/app/models') . DIRECTORY_SEPARATOR);
define('VIEWS_DIR', realpath(__DIR__ . '/app/views') . DIRECTORY_SEPARATOR);
define('LANGUAGES_DIR', realpath(__DIR__ . '/app/languages') . DIRECTORY_SEPARATOR);
define('LIB_DIR', realpath(__DIR__ . '/lib') . DIRECTORY_SEPARATOR);
define('CSS_DIR', __DIR__ . '/public/css' . DIRECTORY_SEPARATOR);
define('IMG_DIR', Config::getConfig('base') . 'public/img/');
define('JS_DIR', __DIR__ . '/public/js' . DIRECTORY_SEPARATOR);
define('LESS_DIR', realpath(__DIR__ . '/public/less') . DIRECTORY_SEPARATOR);
//Set current language
if (!isset($_SESSION[Config::$lang_session])) {
    $_SESSION[Config::$lang_session] = Config::getConfig(Config::$lang);
}
//Running the router
$router = new \Lib\Router();
//Compiling dynamic stylesheet
if (Config::getPlugins('css') == 'lessCSS') {
    $lessFile = glob('public/less/*.less');
    if (sizeof($lessFile) > 0) {
        $less = new lessc();
        foreach ($lessFile as $value) {
            $filenames = explode('/', $value);
            $filename = $filenames[2];
            $less->checkedCompile($value, strstr($value, '/', true) . '/css/' . substr($filename, 0, strpos($filename, '.')) . '.css');
        }
    }
}
//Call caches header
if (Config::getConfig(Config::$cache) == 'true') {
    $router->headerCache();