|
@@ -56,32 +56,53 @@ class Route {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
$uris = array_get($action, 'handles', array($key));
|
|
$uris = array_get($action, 'handles', array($key));
|
|
|
|
|
|
- $this->uris = array_map(array($this, 'extract'), $uris);
|
|
+ $this->uris = array_map(array($this, 'destination'), $uris);
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
+
|
|
$this->bundle = Bundle::handles($this->uris[0]);
|
|
$this->bundle = Bundle::handles($this->uris[0]);
|
|
|
|
|
|
- $this->parameters = array_map('urldecode', $parameters);
|
|
+ $defaults = array_get($action, 'defaults', array());
|
|
|
|
+
|
|
|
|
+ $this->parameters = array_merge($parameters, $defaults);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ foreach ($this->uris as &$uri)
|
|
|
|
+ {
|
|
|
|
+ $uri = $this->transpose($uri, $this->parameters);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- * Retrieve the URI from a given route destination.
|
|
+ * Substitute the parameters in a given URI.
|
|
*
|
|
*
|
|
- * If the request is to the application root, a slash is returned.
|
|
+ * @param string $uri
|
|
- *
|
|
+ * @param array $parameters
|
|
- * @param string $segment
|
|
|
|
* @return string
|
|
* @return string
|
|
*/
|
|
*/
|
|
- protected static function extract($segment)
|
|
+ public static function transpose($uri, $parameters)
|
|
{
|
|
{
|
|
- $uri = substr($segment, strpos($segment, ' ') + 1);
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ foreach ((array) $parameters as $parameter)
|
|
|
|
+ {
|
|
|
|
+ if ( ! is_null($parameter))
|
|
|
|
+ {
|
|
|
|
+ $uri = preg_replace('/\(.+?\)/', $parameter, $uri, 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- return ($uri !== '/') ? trim($uri, '/') : $uri;
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return str_replace(array_keys(Router::$optional), '', $uri);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -92,9 +113,8 @@ class Route {
|
|
public function call()
|
|
public function call()
|
|
{
|
|
{
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
|
|
$response = Filter::run($this->filters('before'), array(), true);
|
|
$response = Filter::run($this->filters('before'), array(), true);
|
|
|
|
|
|
if (is_null($response))
|
|
if (is_null($response))
|
|
@@ -102,6 +122,9 @@ class Route {
|
|
$response = $this->response();
|
|
$response = $this->response();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
$response = Response::prepare($response);
|
|
$response = Response::prepare($response);
|
|
|
|
|
|
Filter::run($this->filters('after'), array($response));
|
|
Filter::run($this->filters('after'), array($response));
|
|
@@ -218,6 +241,39 @@ class Route {
|
|
}));
|
|
}));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * Register a route with the router.
|
|
|
|
+ *
|
|
|
|
+ * <code>
|
|
|
|
+ *
|
|
|
|
+ * Router::register('GET /', function() {return 'Home!';});
|
|
|
|
+ *
|
|
|
|
+ *
|
|
|
|
+ * Router::register(array('GET /', 'GET /home'), function() {return 'Home!';});
|
|
|
|
+ * </code>
|
|
|
|
+ *
|
|
|
|
+ * @param string|array $route
|
|
|
|
+ * @param mixed $action
|
|
|
|
+ * @param bool $https
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+ public static function to($route, $action)
|
|
|
|
+ {
|
|
|
|
+ Router::register($route, $action);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * Register a HTTPS route with the router.
|
|
|
|
+ *
|
|
|
|
+ * @param string|array $route
|
|
|
|
+ * @param mixed $action
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+ public static function secure($route, $action)
|
|
|
|
+ {
|
|
|
|
+ Router::secure($route, $action);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
* Extract the URI string from a route destination.
|
|
* Extract the URI string from a route destination.
|
|
*
|
|
*
|