Browse Source

Added shortcut syntax for route handlers on named routes.

Taylor Otwell 13 years ago
parent
commit
8affa31a02
1 changed files with 17 additions and 2 deletions
  1. 17 2
      system/routing/route.php

+ 17 - 2
system/routing/route.php

@@ -63,9 +63,9 @@ class Route {
 		{
 			$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 @@ class Route {
 		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;
+		}
+	}
+
 }