From 8affa31a02749a55baa744a3be41af3c159d1d6f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2011 09:18:40 -0500 Subject: [PATCH] Added shortcut syntax for route handlers on named routes. --- system/routing/route.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/system/routing/route.php b/system/routing/route.php index c5dd283b..1dbf1709 100644 --- a/system/routing/route.php +++ b/system/routing/route.php @@ -63,9 +63,9 @@ public function call() { $response = isset($this->callback['before']) ? Filter::call($this->callback['before'], array(), true) : null; - if (is_null($response) and isset($this->callback['do'])) + if (is_null($response) and ! is_null($handler = $this->handler())) { - $response = call_user_func_array($this->callback['do'], $this->parameters); + $response = call_user_func_array($handler, $this->parameters); } } @@ -79,4 +79,19 @@ public function call() return $response; } + /** + * Extract the route function from the route. + * + * @return Closure + */ + private function handler() + { + if (isset($this->callback['do'])) return $this->callback['do']; + + foreach ($this->callback as $value) + { + if (is_callable($value)) return $value; + } + } + } \ No newline at end of file