Skip to content

Commit

Permalink
loadResources return void
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraLivadas committed Jul 8, 2020
1 parent 9d6a67f commit 9cb22fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
23 changes: 7 additions & 16 deletions modules/electrophysiology_browser/php/sessions.class.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php declare(strict_types=1);

/**
* This class features the code for the menu portion of the LORIS
* electrophysiology browser module.
Expand Down Expand Up @@ -61,42 +60,34 @@ class Sessions extends \NDB_Page
* @param \User $user The user to load the resources for
* @param ServerRequestInterface $request The PSR15 Request being handled
*
* @return ResponseInterface
* @throws \LorisException If the session is non-numerical or does not exist
*
* @return void
*/
public function loadResources(
\User $user, ServerRequestInterface $request
) : ResponseInterface {
) : void {

$path = $request->getUri()->getPath();
$matches = [];

if (preg_match('#/sessions/(\d+)#', $path, $matches) !== 1) {
return (new \LORIS\Middleware\PageDecorationMiddleware($user))
->process(
$request,
new \LORIS\Http\StringStream("Invalid session")
)->withStatus(404);
throw new \LorisException("Invalid session");
}

$session_id = intval($matches[1]);
try {
$this->timepoint = \NDB_Factory::singleton()->timepoint(
$session_id
);
$this->sessionID = $session_id;
} catch(\LorisException $e) {
return (new \LORIS\Middleware\PageDecorationMiddleware($user))
->process(
$request,
new \LORIS\Http\StringStream("Session not found")
)->withStatus(404);
throw new \LorisException("Session not found");
}

$candID = $this->timepoint->getCandID();
$this->candidate = \Candidate::singleton($candID);

parent::loadResources($user, $request);
return (new \LORIS\Http\Response())
->withBody(new \LORIS\Http\StringStream($this->display() ?? ""));
}

/**
Expand Down
6 changes: 2 additions & 4 deletions php/libraries/NDB_Page.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,11 @@ class NDB_Page implements RequestHandlerInterface
* @param User $user The user to load the resources for
* @param ServerRequestInterface $request The PSR15 Request being handled
*
* @return ResponseInterface
* @return void
*/
public function loadResources(
\User $user, ServerRequestInterface $request
) : ResponseInterface {
return (new \LORIS\Http\Response())
->withBody(new \LORIS\Http\StringStream($this->display() ?? ""));
) : void {
}

/**
Expand Down

0 comments on commit 9cb22fc

Please sign in to comment.