Exemplo n.º 1
0
 public function registerRouting(Container $container, ApplicationServiceProvider $builder)
 {
     $container['handler.login'] = function (Container $container) {
         return new LoginHandler($container['service.authentication'], $container['logger']);
     };
     $container['handler.refreshToken'] = function (Container $container) {
         return new RefreshTokenHandler($container['service.tokens'], $container['logger']);
     };
     $container['handler.logout'] = function (Container $container) {
         return new LogoutHandler($container['service.tokens'], $container['logger']);
     };
     // ErrorHandlers
     $container['error.invalidCredentials'] = function () {
         return new ErrorHandler(LoginFailedException::ERROR_INVALID_CREDENTIALS, 400);
     };
     $container['error.invalidEmailAddress'] = function () {
         return new ErrorHandler(LoginFailedException::ERROR_INVALID_EMAIL_ADDRESS, 400);
     };
     $container['error.invalidToken'] = function () {
         return new ErrorHandler(LoginFailedException::ERROR_INVALID_TOKEN, 401);
     };
     $container['error.systemError'] = function () {
         return new ErrorHandler(LoginFailedException::ERROR_SYSTEM_ERROR, 500);
     };
     $builder->addGenerator(LoginFailedException::ERROR_INVALID_CREDENTIALS, self::JSON_API_CT, 'error.invalidCredentials');
     $builder->addGenerator(LoginFailedException::ERROR_INVALID_EMAIL_ADDRESS, self::JSON_API_CT, 'error.invalidEmailAddress');
     $builder->addGenerator(LoginFailedException::ERROR_INVALID_TOKEN, self::JSON_API_CT, 'error.invalidToken');
     $builder->addGenerator(LoginFailedException::ERROR_SYSTEM_ERROR, self::JSON_API_CT, 'error.systemError');
     // Configure ApiBuilder to use Handlers & Response Generators
     $builder->addParser('POST', $this->uriSegment . '/login', 'handler.login')->addExecutor(LoginHandler::MESSAGE, 'handler.login')->addGenerator(LoginHandler::MESSAGE, self::JSON_API_CT, 'handler.login');
     $builder->addParser('POST', $this->uriSegment . '/token/refresh', 'handler.refreshToken')->addExecutor(RefreshTokenHandler::MESSAGE, 'handler.refreshToken')->addGenerator(RefreshTokenHandler::MESSAGE, self::JSON_API_CT, 'handler.refreshToken');
     $builder->addParser('DELETE', $this->uriSegment . '/logout', 'handler.logout')->addExecutor(LogoutHandler::MESSAGE, 'handler.logout')->addGenerator(LogoutHandler::MESSAGE, self::JSON_API_CT, 'handler.logout');
 }
Exemplo n.º 2
0
 public function registerRouting(Container $container, ApplicationServiceProvider $builder)
 {
     $container['errorHandler.badRequest'] = function () {
         return new ErrorHandler('error.badRequest', 400, 'Bad Request');
     };
     $container['errorHandler.unauthorized'] = function () {
         return new ErrorHandler('error.unauthorized', 401, 'Unauthorized');
     };
     $container['errorHandler.notFound'] = function () {
         return new ErrorHandler('error.notFound', 404, 'Not Found');
     };
     $container['errorHandler.serverError'] = function () {
         return new ErrorHandler('error.serverError', 500, 'Server Error');
     };
     // Add error handlers
     $builder->addExecutor('error.unauthorized', 'errorHandler.unauthorized');
     $builder->addGenerator('error.unauthorized', self::JSON_API_CT, 'errorHandler.unauthorized');
     $builder->addExecutor('error.badRequest', 'errorHandler.badRequest');
     $builder->addGenerator('error.badRequest', self::JSON_API_CT, 'errorHandler.badRequest');
     $builder->addExecutor('error.notFound', 'errorHandler.notFound');
     $builder->addGenerator('error.notFound', self::JSON_API_CT, 'errorHandler.notFound');
     $builder->addExecutor('error.serverError', 'errorHandler.serverError');
     $builder->addGenerator('error.serverError', self::JSON_API_CT, 'errorHandler.serverError');
 }