Ergo\Routing\Router::connect PHP Method

connect() public method

Gives a route template a unique name and a controller to route to
public connect ( $template, $name, $controller = null, $metadata = [] )
    public function connect($template, $name, $controller = null, $metadata = array())
    {
        if (is_object($template)) {
            $this->_customRoutes[$name] = $template;
        } else {
            $this->_routes[$name] = new Route($name, $template);
        }
        if ($metadata) {
            $this->_metadata[$name] = $metadata;
        }
        if ($controller) {
            $this->_controllers[$name] = $controller;
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testCustomRoute()
 {
     $urlPath = '/user/24';
     $mockRoute = \Mockery::mock('Erg\\Routing\\Route');
     $mockRoute->shouldReceive('getMatch')->with($urlPath, array())->once()->andReturn(new \Ergo\Routing\RouteMatch('user', array()))->shouldReceive('getName')->andReturn('user');
     $router = new Router();
     $router->connect($mockRoute, 'Custom.view');
     $this->assertEquals($router->lookup($urlPath)->getName(), 'user');
 }
All Usage Examples Of Ergo\Routing\Router::connect