From bb6f56ef8cbb5f255a127097ecda9295a929f475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Fri, 15 Jan 2016 09:37:23 +0100 Subject: [PATCH] [BUGFIX] Fixed some ressources not working after latest update. - Optimisations + cleanup. --- src/Pecee/SimpleRouter/RouterEntry.php | 4 -- src/Pecee/SimpleRouter/RouterResource.php | 79 +++++++++++------------ src/Pecee/SimpleRouter/RouterRoute.php | 8 +-- 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/src/Pecee/SimpleRouter/RouterEntry.php b/src/Pecee/SimpleRouter/RouterEntry.php index 5ed231a..098bb86 100644 --- a/src/Pecee/SimpleRouter/RouterEntry.php +++ b/src/Pecee/SimpleRouter/RouterEntry.php @@ -178,10 +178,6 @@ abstract class RouterEntry { public function getMergeableSettings() { $settings = $this->settings; - /*if(isset($settings['middleware'])) { - unset($settings['middleware']); - }*/ - if(isset($settings['prefix'])) { unset($settings['prefix']); } diff --git a/src/Pecee/SimpleRouter/RouterResource.php b/src/Pecee/SimpleRouter/RouterResource.php index a9733e6..754af0b 100644 --- a/src/Pecee/SimpleRouter/RouterResource.php +++ b/src/Pecee/SimpleRouter/RouterResource.php @@ -53,50 +53,45 @@ class RouterResource extends RouterEntry { $parameters = $this->parseParameters($route, $url, '[0-9]*?'); - if($parameters !== null) { - - if(is_array($parameters)) { - $parameters = array_merge($this->parameters, $parameters); - } - - $action = $parameters['action']; - unset($parameters['action']); - - // Delete - if($request->getMethod() === self::REQUEST_TYPE_DELETE && $this->postMethod === self::REQUEST_TYPE_POST) { - return $this->call('destroy', $parameters); - } - - // Update - if(in_array($request->getMethod(), array(self::REQUEST_TYPE_PATCH, self::REQUEST_TYPE_PUT)) && $this->postMethod === self::REQUEST_TYPE_POST) { - return $this->call('update', $parameters); - } - - // Edit - if(isset($action) && strtolower($action) === 'edit' && $this->postMethod === self::REQUEST_TYPE_GET) { - return $this->call('edit', $parameters); - } - - // Create - if(strtolower($action) === 'create' && $request->getMethod() === self::REQUEST_TYPE_GET) { - return $this->call('create', $parameters); - } - - // Save - if($this->postMethod === self::REQUEST_TYPE_POST) { - return $this->call('store', $parameters); - } - - // Show - if(isset($parameters['id']) && $this->postMethod === self::REQUEST_TYPE_GET) { - return $this->call('show', $parameters); - } - - // Index - return $this->call('index', $parameters); + if(is_array($parameters)) { + $parameters = array_merge($this->parameters, $parameters); } - return null; + $action = $parameters['action']; + unset($parameters['action']); + + // Delete + if($request->getMethod() === self::REQUEST_TYPE_DELETE && $this->postMethod === self::REQUEST_TYPE_POST) { + return $this->call('destroy', $parameters); + } + + // Update + if(in_array($request->getMethod(), array(self::REQUEST_TYPE_PATCH, self::REQUEST_TYPE_PUT)) && $this->postMethod === self::REQUEST_TYPE_POST) { + return $this->call('update', $parameters); + } + + // Edit + if(isset($action) && strtolower($action) === 'edit' && $this->postMethod === self::REQUEST_TYPE_GET) { + return $this->call('edit', $parameters); + } + + // Create + if(strtolower($action) === 'create' && $request->getMethod() === self::REQUEST_TYPE_GET) { + return $this->call('create', $parameters); + } + + // Save + if($this->postMethod === self::REQUEST_TYPE_POST) { + return $this->call('store', $parameters); + } + + // Show + if(isset($parameters['id']) && $this->postMethod === self::REQUEST_TYPE_GET) { + return $this->call('show', $parameters); + } + + // Index + return $this->call('index', $parameters); } /** diff --git a/src/Pecee/SimpleRouter/RouterRoute.php b/src/Pecee/SimpleRouter/RouterRoute.php index 3321728..66fe161 100644 --- a/src/Pecee/SimpleRouter/RouterRoute.php +++ b/src/Pecee/SimpleRouter/RouterRoute.php @@ -40,13 +40,7 @@ class RouterRoute extends RouterEntry { $parameters = $this->parseParameters($route, $url); if($parameters !== null) { - - //if(is_array($this->parameters)) { - // $this->parameters = array_merge($this->parameters, $parameters); - //} else { - $this->parameters = $parameters; - //} - + $this->parameters = $parameters; return true; }