diff --git a/src/Controller/Mapper/Rest.php b/src/Controller/Mapper/Rest.php index 33a891db..767048b0 100644 --- a/src/Controller/Mapper/Rest.php +++ b/src/Controller/Mapper/Rest.php @@ -28,7 +28,8 @@ protected function prepareRequest() if (count($params)) { $primaryKeys = $this->crud->getPrimaryKey(); - $primaryValues = explode('-', array_shift($params)); + + $primaryValues = explode('-', array_shift($params), count($primaryKeys)); $this->primary = array_combine($primaryKeys, $primaryValues); } diff --git a/tests/src/BootstrapTest.php b/tests/src/BootstrapTest.php index 6a39581a..dbe411a8 100644 --- a/tests/src/BootstrapTest.php +++ b/tests/src/BootstrapTest.php @@ -10,6 +10,12 @@ namespace Bluz\Tests; use Bluz\Application\Application; +use Bluz\Application\Exception\ForbiddenException; +use Bluz\Application\Exception\RedirectException; +use Bluz\Controller\Controller; +use Bluz\Proxy\Layout; +use Bluz\Proxy\Request; +use Bluz\Proxy\Response; /** * Bootstrap @@ -60,27 +66,6 @@ public function getController() return $this->dispatchController; } - /** - * @param string $module - * @param string $controller - * @param array $params - * - * @return \Bluz\Controller\Controller - * @throws \Exception - */ - public function dispatch($module, $controller, array $params = []) - { - $this->dispatchModule = $module; - $this->dispatchController = $controller; - - try { - return parent::dispatch($module, $controller, $params); - } catch (\Exception $e) { - $this->setException($e); - throw $e; - } - } - /** * setException * @@ -91,6 +76,9 @@ public function dispatch($module, $controller, array $params = []) public function setException($exception) { $this->exception = $exception; + + codecept_debug(' ## '. $exception->getCode()); + codecept_debug(' ## '. $exception->getMessage()); } /** @@ -102,4 +90,49 @@ public function getException() { return $this->exception; } + + /** + * @inheritdoc + */ + protected function doProcess() + { + $module = Request::getModule(); + $controller = Request::getController(); + $params = Request::getParams(); + + // try to dispatch controller + try { + codecept_debug(''); + codecept_debug(' >> '. $module .'/'. $controller); + + // dispatch controller + $result = $this->dispatch($module, $controller, $params); + } catch (ForbiddenException $e) { + $this->setException($e); + $result = $this->forbidden($e); + } catch (RedirectException $e) { + $this->setException($e); + // redirect to URL + $result = $this->redirect($e->getUrl()); + } catch (\Exception $e) { + $this->setException($e); + $result = $this->error($e); + } + + if ($result instanceof Controller) { + $this->dispatchModule = $result->getModule(); + $this->dispatchController = $result->getController(); + codecept_debug(' << '. $this->getModule() .'/'. $this->getController()); + } + + // setup layout, if needed + if ($this->useLayout()) { + // render view to layout + // needed for headScript and headStyle helpers + Layout::setContent($result->render()); + Response::setBody(Layout::getInstance()); + } else { + Response::setBody($result); + } + } }