Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Added override for delete verb when no id send to list
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Jan 20, 2015
1 parent 9c11598 commit 92031a9
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,30 @@ public function onDispatch(MvcEvent $e)
// Check for an API-Problem in the event
$return = $e->getParam('api-problem', false);

// If no API-Problem, dispatch the parent event
if (!$return) {
$return = parent::onDispatch($e);
// Override RESTful methods
$request = $e->getRequest();
$method = strtolower($request->getMethod());

switch ($method) {
case 'delete':
$routeMatch = $e->getRouteMatch();
$id = $this->getIdentifier($routeMatch, $request);
$data = $this->processBodyContent($request);

if ($id !== false) {
$return = parent::onDispatch($e);
break;
}

$action = 'deleteList';
$return = $this->deleteList($data);
break;
default:
// If no API-Problem, dispatch the parent event
$return = parent::onDispatch($e);
break;
}
}

if (!$return instanceof ApiProblem
Expand All @@ -350,6 +371,7 @@ public function onDispatch(MvcEvent $e)
$viewModel = new ContentNegotiationViewModel(array('payload' => $return));
$viewModel->setTerminal(true);
$e->setResult($viewModel);

return $viewModel;
}

Expand Down

0 comments on commit 92031a9

Please sign in to comment.