lithium\net\http\Router::connect PHP Method

connect() public static method

A callable can be passed in place of $options. In this case the callable acts as a *route handler*. Route handlers should return an instance of lithium\net\http\Response and can be used to short-circuit the framework's lookup and invocation of controller actions: Router::connect('/photos/{:id:[0-9]+}.jpg', array(), function($request) { return new Response(array( 'headers' => array('Content-type' => 'image/jpeg'), 'body' => Photos::first($request->id)->bytes() )); });
See also: lithium\net\http\Route
See also: lithium\net\http\Route::$_handler
See also: lithium\net\http\Router::parse()
See also: lithium\net\http\Router::match()
See also: lithium\net\http\Router::_parseString()
See also: lithium\net\http\Response
public static connect ( string | object $template, array | string $params = [], array | callable $options = [] ) : array
$template string | object An empty string, a route string `/` or an instance of `lithium\net\http\Route`.
$params array | string An array describing the default or required elements of the route or alternatively a path string i.e. `Posts::index`.
$options array | callable Either an array of options (`'handler'`, `'formatters'`, `'modifiers'`, `'unicode'` as well as any options for `Route`) or a callable that will be used as a route handler.
return array Array of routes
    public static function connect($template, $params = array(), $options = array())
    {
        if (is_array($options) && isset($options['scope'])) {
            $name = $options['scope'];
        } else {
            $name = static::$_scope;
        }
        if (is_object($template)) {
            return static::$_configurations[$name][] = $template;
        }
        if (is_string($params)) {
            $params = static::_parseString($params, false);
        }
        if (isset($params[0]) && is_array($tmp = static::_parseString($params[0], false))) {
            unset($params[0]);
            $params = $tmp + $params;
        }
        $params = static::_parseController($params);
        if (is_callable($options)) {
            $options = array('handler' => $options);
        }
        $config = compact('template', 'params') + $options + array('formatters' => static::formatters(), 'modifiers' => static::modifiers(), 'unicode' => static::$_unicode);
        return static::$_configurations[$name][] = static::_instance('route', $config);
    }

Usage Example

Exemplo n.º 1
0
 public function tearDown()
 {
     Router::reset();
     foreach ($this->_routes as $route) {
         Router::connect($route);
     }
 }
All Usage Examples Of lithium\net\http\Router::connect