/**
  * @Before("execution(public Autenticacao\Controllers\ListaUsuarioController->*(*))")
  * 
  * @param MethodInvocation $invocation            
  */
 public function beforeMethodExecution(MethodInvocation $invocation)
 {
     $container = Container::obtemInstancia();
     $mapper = $container->mapper;
     $headers = apache_request_headers();
     $token = null;
     $bearer = null;
     $resposta = new stdClass();
     $resposta->success = false;
     if (!isset($headers['Authorization'])) {
         die(json_encode($resposta));
     }
     $authorization = (string) $headers['Authorization'];
     $acessoToken = new AcessoToken($mapper);
     if ($acessoToken->validaFormatoDoToken($authorization)) {
         list($bearer, $token) = explode(" ", $authorization);
     }
     $acessoTokenRepository = new AcessoTokenRepository($mapper);
     $sessaoValida = $acessoTokenRepository->obtemPorTokenValido($token);
     if (!$sessaoValida) {
         die(json_encode($resposta));
     }
 }
Exemplo n.º 2
0
define('APPLICATION_PATH', dirname(realpath(__FILE__)) . '/../');
define('APPLICATION_ENVIRONMENT', 'desenvolvimento');
switch (APPLICATION_ENVIRONMENT) {
    case 'desenvolvimento':
        error_reporting(E_ALL);
        ini_set('display_errors', 1);
        break;
    case 'teste':
    case 'producao':
        error_reporting(0);
        break;
    default:
        exit('O ambiente do aplicativo não está definida corretamente .');
}
require_once APPLICATION_PATH . 'vendor/autoload.php';
$container = \Autenticacao\Container::obtemInstancia();
$applicationAspectKernel = \Autenticacao\ApplicationAspectKernel::getInstance();
$applicationAspectKernel->init(array('debug' => true, 'cacheDir' => APPLICATION_PATH . 'cache/'));
$mapper = $container->mapper;
$mapper->entityNamespace = '\\Autenticacao\\Entities\\';
$router = $container->router;
// MODULO DE USUARIO
$router->post(BASE_URL . "public/usuario", "\\Autenticacao\\Controllers\\UsuarioController", array($container->mapper))->accept(array('application/json' => function ($obj) {
    echo json_encode($obj);
}));
$router->get(BASE_URL . "public/usuario/*", "\\Autenticacao\\Controllers\\UsuarioController", array($container->mapper))->accept(array('application/json' => function ($obj) {
    echo json_encode($obj);
}));
$router->put(BASE_URL . "public/usuario/*", "\\Autenticacao\\Controllers\\UsuarioController", array($container->mapper))->accept(array('application/json' => function ($obj) {
    echo json_encode($obj);
}));