From 92031a92b3dbdc055a1b5b15841cfde401aa8752 Mon Sep 17 00:00:00 2001 From: Tom Anderson Date: Tue, 20 Jan 2015 13:07:20 -0700 Subject: [PATCH] Added override for delete verb when no id send to list --- src/RestController.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/RestController.php b/src/RestController.php index 6f5c0ad..8cdb654 100644 --- a/src/RestController.php +++ b/src/RestController.php @@ -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 @@ -350,6 +371,7 @@ public function onDispatch(MvcEvent $e) $viewModel = new ContentNegotiationViewModel(array('payload' => $return)); $viewModel->setTerminal(true); $e->setResult($viewModel); + return $viewModel; }