with_session = true; parent::__construct($dispatcher); } public function before_filter(&$action, &$args) { parent::before_filter($action, $args); //All the work is done by the OAT-SA library and //the implementation of its interfaces in Stud.IP. //Only the handler changes for the endpoints. $reg_manager = new RegistrationManager(); $line_item_repo = new LineItemRepository(); $validator = new RequestAccessTokenValidator($reg_manager); $handler = null; if ($action === 'line_item') { if (empty($args)) { if (Request::isPut()) { //Update a line item: $handler = new UpdateLineItemServiceServerRequestHandler($line_item_repo); } elseif (Request::isDelete()) { //Delete a line item: $handler = new DeleteLineItemServiceServerRequestHandler($line_item_repo); } else { //Get a line item: $handler = new GetLineItemServiceServerRequestHandler($line_item_repo); } } elseif ($args[0] === 'results') { $handler = new ResultServiceServerRequestHandler($line_item_repo, new Studip\LTI13a\ResultRepository()); } elseif ($args[0] === 'scores') { $handler = new ScoreServiceServerRequestHandler($line_item_repo,new \Studip\LTI13a\ScoreRepository()); } } elseif ($action === 'line_items') { if (Request::isPost()) { //Create a line item: $handler = new CreateLineItemServiceServerRequestHandler($line_item_repo); } else { //List line items: $handler = new ListLineItemsServiceServerRequestHandler($line_item_repo); } } else { //Invalid endpoint. throw new AccessDeniedException(studip_interpolate('Invalid endpoint: %{endpoint}', ['endpoint' => $action])); } if (!$handler) { throw new \Studip\LTIException('No handler available for this request.'); } $server = new LtiServiceServer($validator, $handler); $this->renderPsrResponse($server->handle($this->getPsrRequest())); } /** * This is the endpoint for the LTI AGS lineitem service. * * @return void */ public function line_item_action(): void { //Nothing here. All is done in the before_filter. } /** * This is the endpoint for the LTI AGS lineitems service. * * @return void */ public function line_items_action(): void { //Nothing here. All is done in the before_filter. } }