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'); }
public function registerRouting(Container $container, ApplicationServiceProvider $builder) { // Pages API Calls $container['handler.pages.create'] = function (Container $container) { return new CreatePageHandler($container['repository.pages'], $container['logger']); }; $container['handler.pages.list'] = function (Container $container) { return new ListPagesHandler($container['repository.pages'], $container['logger']); }; $container['handler.pages.get'] = function (Container $container) { return new GetPageHandler($container['repository.pages'], $container['logger']); }; $container['handler.pages.update'] = function (Container $container) { return new UpdatePageHandler($container['repository.pages'], $container['logger']); }; $container['handler.pages.reorder'] = function (Container $container) { return new ReorderPagesHandler($container['repository.pages'], $container['logger']); }; $container['handler.pages.delete'] = function (Container $container) { return new DeletePageHandler($container['repository.pages'], $container['logger']); }; // PageBlocks API Calls $container['handler.pageBlocks.create'] = function (Container $container) { return new AddPageBlockHandler($container['repository.pages'], $container['siteContent.blockTypes'], $container['logger']); }; $container['handler.pageBlocks.get'] = function (Container $container) { return new GetPageBlockHandler($container['repository.pages'], $container['logger']); }; $container['handler.pageBlocks.update'] = function (Container $container) { return new UpdatePageBlockHandler($container['repository.pages'], $container['siteContent.blockTypes'], $container['logger']); }; $container['handler.pageBlocks.delete'] = function (Container $container) { return new DeletePageBlockHandler($container['repository.pages'], $container['logger']); }; // Response Generators for both $container['responseGenerator.pages.single'] = function (Container $container) { return new SingleEntityGenerator(new PageSerializer(), null, $container['logger']); }; $container['responseGenerator.pages.multi'] = function (Container $container) { return new MultiEntityGenerator(new PageSerializer(), function (ResponseInterface $response) : array { $metaData = ['parent_uuid' => isset($response['parent_uuid']) && $response['parent_uuid'] instanceof UuidInterface ? $response['parent_uuid']->toString() : null]; return $metaData; }, $container['logger']); }; $container['responseGenerator.pageBlocks.single'] = function (Container $container) { return new SingleEntityGenerator(new PageBlockSerializer(), null, $container['logger']); }; // Configure ApiBuilder to use Handlers & Response Generators $builder->addParser('POST', $this->uriSegment, 'handler.pages.create')->addExecutor(CreatePageHandler::MESSAGE, 'handler.pages.create')->addGenerator(CreatePageHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pages.single'); $builder->addParser('GET', $this->uriSegment, 'handler.pages.list')->addExecutor(ListPagesHandler::MESSAGE, 'handler.pages.list')->addGenerator(ListPagesHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pages.multi'); $builder->addParser('GET', $this->uriSegment . '/{uuid:[0-9a-z\\-]+}', 'handler.pages.get')->addExecutor(GetPageHandler::MESSAGE, 'handler.pages.get')->addGenerator(GetPageHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pages.single'); $builder->addParser('PATCH', $this->uriSegment . '/{uuid:[0-9a-z\\-]+}', 'handler.pages.update')->addExecutor(UpdatePageHandler::MESSAGE, 'handler.pages.update')->addGenerator(UpdatePageHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pages.single'); $builder->addParser('PATCH', $this->uriSegment . '/{parent_uuid:[0-9a-z\\-]+}/reorder', 'handler.pages.reorder')->addExecutor(ReorderPagesHandler::MESSAGE, 'handler.pages.reorder')->addGenerator(ReorderPagesHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pages.multi'); $builder->addParser('DELETE', $this->uriSegment . '/{uuid:[0-9a-z\\-]+}', 'handler.pages.delete')->addExecutor(DeletePageHandler::MESSAGE, 'handler.pages.delete')->addGenerator(DeletePageHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pages.single'); $builder->addParser('POST', $this->uriSegment . '/{page_uuid:[0-9a-z\\-]+}/blocks', 'handler.pageBlocks.create')->addExecutor(AddPageBlockHandler::MESSAGE, 'handler.pageBlocks.create')->addGenerator(AddPageBlockHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pageBlocks.single'); $builder->addParser('GET', $this->uriSegment . '/{page_uuid:[0-9a-z\\-]+}/blocks/{uuid:[0-9a-z\\-]+}', 'handler.pageBlocks.get')->addExecutor(GetPageBlockHandler::MESSAGE, 'handler.pageBlocks.get')->addGenerator(GetPageBlockHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pageBlocks.single'); $builder->addParser('PATCH', $this->uriSegment . '/{page_uuid:[0-9a-z\\-]+}/blocks/{uuid:[0-9a-z\\-]+}', 'handler.pageBlocks.update')->addExecutor(UpdatePageBlockHandler::MESSAGE, 'handler.pageBlocks.update')->addGenerator(UpdatePageBlockHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pageBlocks.single'); $builder->addParser('DELETE', $this->uriSegment . '/{page_uuid:[0-9a-z\\-]+}/blocks/{uuid:[0-9a-z\\-]+}', 'handler.pageBlocks.delete')->addExecutor(DeletePageBlockHandler::MESSAGE, 'handler.pageBlocks.delete')->addGenerator(DeletePageBlockHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.pageBlocks.single'); }
public function registerRouting(Container $container, ApplicationServiceProvider $builder) { // Files API Calls $container['requestParser.images.getEdited'] = function (Container $container) { return new OperationsHttpRequestParser(GetEditedImageHandler::MESSAGE, $container['fileManager.helper']); }; $container['handler.images.getEdited'] = function (Container $container) { return new GetEditedImageHandler($container['repository.images'], $container['imagine'], $container['logger']); }; $container['requestParser.images.storeEdited'] = function (Container $container) { return new OperationsHttpRequestParser(StoreEditedImageHandler::MESSAGE, $container['fileManager.helper']); }; $container['handler.images.storeEdited'] = function (Container $container) { return new StoreEditedImageHandler($container['repository.images'], $container['imagine'], $container['fileManager.helper'], $container['logger']); }; // Configure ApiBuilder to use Handlers & Response Generators $builder->addParser('GET', $this->uriSegment . '/f/{path:.+}', 'requestParser.images.getEdited')->addExecutor(GetEditedImageHandler::MESSAGE, 'handler.images.getEdited')->addGenerator(GetEditedImageHandler::MESSAGE, '*/*', 'handler.images.getEdited'); $builder->addParser('PUT', $this->uriSegment . '/d/{path:.*}', 'requestParser.images.storeEdited')->addExecutor(StoreEditedImageHandler::MESSAGE, 'handler.files.storeEdited')->addGenerator(StoreEditedImageHandler::MESSAGE, '*/*', 'responseGenerator.files.single'); }
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'); }
public function registerRouting(Container $container, ApplicationServiceProvider $builder) { // Files API Calls $container['handler.files.upload'] = function (Container $container) { return new UploadFileHandler($container['repository.files'], $container['fileManager.helper'], $container['logger']); }; $container['handler.files.get'] = function (Container $container) { return new DownloadFileHandler($container['repository.files'], $container['fileManager.helper'], $container['logger']); }; $container['handler.files.getDirectory'] = function (Container $container) { return new GetDirectoryListingHandler($container['repository.files'], $container['fileManager.helper'], $container['logger']); }; $container['handler.files.delete'] = function (Container $container) { return new DeleteFileHandler($container['repository.files'], $container['fileManager.helper'], $container['logger']); }; $container['handler.files.rename'] = function (Container $container) { return new RenameFileHandler($container['repository.files'], $container['fileManager.helper'], $container['logger']); }; $container['handler.files.move'] = function (Container $container) { return new MoveFileHandler($container['repository.files'], $container['fileManager.helper'], $container['logger']); }; // Response Generators for both $container['responseGenerator.files.single'] = function (Container $container) { return new SingleEntityGenerator(new FileSerializer(), null, $container['logger']); }; $container['responseGenerator.files.multi'] = function (Container $container) { return new MultiEntityGenerator(new FileSerializer(), null, $container['logger']); }; $container['responseGenerator.directoryListing'] = function (Container $container) { return new SingleEntityGenerator(new DirectoryListingSerializer(), null, $container['logger']); }; // Configure ApiBuilder to use Handlers & Response Generators $builder->addParser('POST', $this->uriSegment . '/f/{path:.+}', 'handler.files.upload')->addExecutor(UploadFileHandler::MESSAGE, 'handler.files.upload')->addGenerator(UploadFileHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.files.multi'); $builder->addParser('GET', $this->uriSegment . '/f/{path:.+}', 'handler.files.download')->addExecutor(DownloadFileHandler::MESSAGE, 'handler.files.download')->addGenerator(DownloadFileHandler::MESSAGE, '*/*', 'handler.files.download'); $builder->addParser('GET', $this->uriSegment . '/d/{path:.*}', 'handler.files.getDirectory')->addExecutor(GetDirectoryListingHandler::MESSAGE, 'handler.files.getDirectory')->addGenerator(GetDirectoryListingHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.directoryListing'); $builder->addParser('DELETE', $this->uriSegment . '/f/{path:.+}', 'handler.files.delete')->addExecutor(DeleteFileHandler::MESSAGE, 'handler.files.delete')->addGenerator(DeleteFileHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.files.single'); $builder->addParser('PATCH', $this->uriSegment . '/rename/{path:.+}', 'handler.files.rename')->addExecutor(RenameFileHandler::MESSAGE, 'handler.files.rename')->addGenerator(RenameFileHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.files.single'); $builder->addParser('PATCH', $this->uriSegment . '/move/{path:.+}', 'handler.files.move')->addExecutor(MoveFileHandler::MESSAGE, 'handler.files.move')->addGenerator(MoveFileHandler::MESSAGE, self::JSON_API_CT, 'responseGenerator.files.single'); }