From 3c3dcdf8df0df143b217fdb9646f80a0ad0560a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Sun, 11 Oct 2015 10:43:35 +0200 Subject: [PATCH] =?UTF-8?q?[FEATURE]=C2=A0Added=20getIdentifier=20method?= =?UTF-8?q?=20to=20RouterBase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed getter for getLoadedRoute --- src/Pecee/SimpleRouter/RouterBase.php | 7 +++++-- src/Pecee/SimpleRouter/RouterEntry.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index 34e97bc..1a85a2d 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -120,8 +120,11 @@ class RouterBase { /** * @return RouterEntry */ - public function getLoadedClass() { - return $this->loadedClass; + public function getLoadedRoute() { + if(!($this->loadedRoute instanceof RouterGroup)) { + return $this->loadedRoute; + } + return null; } /** diff --git a/src/Pecee/SimpleRouter/RouterEntry.php b/src/Pecee/SimpleRouter/RouterEntry.php index 70cfe7f..79d402f 100644 --- a/src/Pecee/SimpleRouter/RouterEntry.php +++ b/src/Pecee/SimpleRouter/RouterEntry.php @@ -33,6 +33,20 @@ abstract class RouterEntry { return new $name(); } + /** + * Returns callback name/identifier for the current route based on the callback. + * Useful if you need to get a unique identifier for the loaded route, for instance + * when using translations etc. + * + * @return string + */ + public function getIdentifier() { + if(strpos($this->callback, '@') !== false) { + return $this->callback; + } + return 'function_' . md5($this->callback); + } + /** * @param string $callback * @return self;