Example #1
0
function bootstrap(RespectMapper $mapper, RespectRouter $router, RespectContainer $config)
{
    Model\Model::setConn($mapper);
    $router->any('/**', 'Application\\Helper\\Mvc\\Router');
    /**
     * Seta o retorno de todas as rotas como resposta em JSON;
     */
    $rotas[''] = $router->always('Accept', array('application/json' => function ($data) {
        header('Content-type: application/json');
        if (v::string()->validate($data)) {
            $data = array($data);
        }
        return json_encode($data, true);
    }));
    /**
     * Rota caso ocorra algum erro
     */
    $router->errorRoute(function ($e) {
        var_dump($e);
    });
    /**
     * Rota caso ocorra alguma excessão
     */
    $router->exceptionRoute(function ($e) {
        var_dump($e);
    });
    /**
     * Rotas Configuradas pelo config.ini
     */
    if (empty($config->routes)) {
        return;
    }
    foreach ($config->routes as $route) {
        $url = $route->url;
        $class_controller = $route->controller;
        $params = isset($route->params) ? $route->params : array();
        $router->get($url, $class_controller, $params);
    }
}
Example #2
0
<?php

define('DS', DIRECTORY_SEPARATOR);
define('APP_ROOT', __DIR__ . DS . '..');
use Respect\Config\Container;
use Respect\Rest\Router;
chdir(APP_ROOT);
$composer_autoload = APP_ROOT . DS . 'vendor' . DS . 'autoload.php';
if (false === is_file($composer_autoload)) {
    throw new \Exception('Por favor, instale as dependências do Composer');
}
require $composer_autoload;
$config = new Container(APP_ROOT . DS . 'config' . DS . 'app.ini');
$app = $config->application;
ini_set('display_errors', $app->display_errors);
error_reporting($app->error_reporting);
date_default_timezone_set($app->timezone);
setlocale(LC_ALL, 'pt_BR');
define('APP_NAME', $app->app_name);
$r = new Router();
$r->get('/', 'Wadmin\\Routes\\GenericRoute');
$r->get('/*', 'Wadmin\\Routes\\GenericRoute');
$r->always('Accept', array('text/html' => new Common\Routine\Twig($app->twig)));
Example #3
0
 /**
  * @covers Respect\Rest\Router::always
  * #64
  */
 public function test_always_can_take_multiple_parameters_for_routine_constructor()
 {
     $this->assertEmpty(DummyRoutine::$result);
     $r3 = new \Respect\Rest\Router();
     $r3->always('dummyRoutine', 'arg1', 'arg2', 'arg3');
     $this->assertEquals('arg1, arg2, arg3', DummyRoutine::$result);
 }