get() public static method

A specific route can be retrived by providing its index. All connected routes inside all scopes may be retrieved by providing null instead of the route index. To retrieve all routes for the current scope only, pass true for the $scope parameter.
public static get ( integer $route = null, string | boolean $scope = null ) : object | array | null
$route integer Index of the route.
$scope string | boolean Name of the scope to get routes from. Uses default scope if `true`.
return object | array | null If $route is an integer, returns the route object at given index or if that fails returns `null`. If $route is `null` returns an array of routes or scopes with their respective routes depending on the value of $scope.
Esempio n. 1
0
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}');
     $this->subject = new Simple(array('request' => new Request(array('base' => '', 'env' => array('HTTP_HOST' => 'foo.local')))));
 }
Esempio n. 2
0
 protected function _saveCtrlContext()
 {
     $this->_context['scope'] = Router::scope(false);
     $this->_context['routes'] = Router::get();
     $this->_context['scopes'] = Router::attached();
     Router::reset();
 }
Esempio n. 3
0
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}');
     $this->subject = new Simple();
 }
Esempio n. 4
0
 /**
  * Initialize test by creating a new object instance with a default context.
  */
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}/{:id}.{:type}');
     Router::connect('/{:controller}/{:action}.{:type}');
     $this->context = new MockRenderer(array('request' => new Request(array('base' => '', 'env' => array('HTTP_HOST' => 'foo.local'))), 'response' => new Response()));
     $this->html = new Html(array('context' => &$this->context));
 }
Esempio n. 5
0
 /**
  * Initialize test by creating a new object instance with a default context.
  *
  * @return void
  */
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}/{:id}.{:type}');
     Router::connect('/{:controller}/{:action}.{:type}');
     $this->context = new MockHtmlRenderer();
     $this->html = new Html(array('context' => &$this->context));
 }
Esempio n. 6
0
 /**
  * Initialize test by creating a new object instance with a default context.
  */
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/test', 'Test::index');
     Router::connect('/test2', 'TestTwo::index');
     $this->context = new MockRenderer(array('request' => new Request(array('url' => '/test', 'env' => array('HTTP_HOST' => 'foo.local'))), 'response' => new Response()));
     $this->backend = new Backend(array('context' => &$this->context));
 }
Esempio n. 7
0
 /**
  * Initialize test by creating a new object instance with a default context.
  *
  * @return void
  */
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::connect(null);
     Router::connect('/{:controller}/{:action}/{:id}.{:type}', array('id' => null));
     Router::connect('/{:controller}/{:action}');
     $this->context = new MockFormRenderer();
     $this->form = new Form(array('context' => $this->context));
 }
Esempio n. 8
0
 /**
  * Lists all connected routes to the router. This is a convenience
  * alias for the `show()` method.
  *
  * Example:
  * {{{
  * li3 route
  * li3 route all
  * }}}
  *
  * Will return an output similar to:
  *
  * {{{
  * Template                        	Params
  * --------                        	------
  * /                               	{"controller":"pages","action":"view"}
  * /pages/{:args}                  	{"controller":"pages","action":"view"}
  * /{:slug:[\w\-]+}                	{"controller":"posts","action":"show"}
  * /{:controller}/{:action}/{:args}	{"action":"index"}
  * }}}
  *
  * @return void
  */
 public function all()
 {
     $routes = Router::get();
     $columns = array(array('Template', 'Params'), array('--------', '------'));
     foreach ($routes as $route) {
         $info = $route->export();
         $columns[] = array($info['template'], json_encode($info['params']));
     }
     $this->columns($columns);
 }
Esempio n. 9
0
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}/page/{:page:[0-9]+}');
     $request = new Request();
     $request->params = array('controller' => 'posts', 'action' => 'index');
     $request->persist = array('controller');
     $this->context = new MockRenderer(compact('request'));
     $this->pagination = new Pagination(array('context' => $this->context));
 }
Esempio n. 10
0
 /**
  * Initialize test by creating a new object instance with a default context.
  */
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}/{:id}.{:type}', array('id' => null));
     Router::connect('/{:controller}/{:action}/{:args}');
     $request = new Request();
     $request->params = array('controller' => 'posts', 'action' => 'index');
     $request->persist = array('controller');
     $this->context = new MockFormRenderer(compact('request'));
     $this->form = new Form(array('context' => $this->context));
     $this->base = $this->context->request()->env('base') . '/';
 }
Esempio n. 11
0
 function setup()
 {
     // Route
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}/{:id}.{:type}');
     Router::connect('/{:controller}/{:action}.{:type}');
     // Info
     $this->account = sprintf('UA-%05d-X', rand(1, 99999));
     // Tracking
     Trackers::add('test', array('account' => $this->account, 'adapter' => 'GoogleAnalytics'));
     // Context
     $this->context = new MockHtmlRenderer(array('request' => new Request(array('base' => '', 'env' => array('HTTP_HOST' => 'foo.local'))), 'response' => new Response()));
     // Analytics
     $this->analytics = new Analytics(array('context' => &$this->context));
 }
Esempio n. 12
0
 /**
  * Test if the routes.php file is loaded correctly and the
  * routes are connected to the router.
  */
 public function testRouteLoading()
 {
     $this->assertEmpty(Router::get(null, true));
     $command = new Route(array('routes' => $this->_config['routes']));
     $this->assertCount(4, Router::get(null, true));
     Router::reset();
     $request = new Request();
     $request->params['env'] = 'production';
     $command = new Route(compact('request') + array('routes' => $this->_config['routes']));
     $this->assertCount(2, Router::get(null, true));
 }
Esempio n. 13
0
 /**
  * Test if the routes.php file is loaded correctly and the
  * routes are connected to the router.
  */
 public function testRouteLoading()
 {
     $this->assertFalse(Router::get());
     $command = new Route(array('routes' => $this->_config['routes']));
     $this->assertEqual(4, count(Router::get()));
     Router::reset();
     $request = new Request();
     $request->params['env'] = 'production';
     $command = new Route(compact('request') + array('routes' => $this->_config['routes']));
     $this->assertEqual(2, count(Router::get()));
 }
Esempio n. 14
0
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
 }
Esempio n. 15
0
 public function setDefaultRoute()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}');
 }
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::connect(null);
 }
 /**
  * Tests getting routes using `Router::get()`, and checking to see if the routes returned match
  * the routes connected.
  */
 public function testRouteRetrieval()
 {
     $expected = Router::connect('/hello', array('controller' => 'posts', 'action' => 'index'));
     $result = Router::get(0);
     $this->assertIdentical($expected, $result);
     list($result) = Router::get();
     $this->assertIdentical($expected, $result);
 }
Esempio n. 18
0
 public function testRouteRetrievalWithScope()
 {
     Router::scope('loc1', function () use(&$expected) {
         $expected = Router::connect('/hello', array('controller' => 'Posts', 'action' => 'index'));
     });
     $result = Router::get(0, true);
     $this->assertIdentical(null, $result);
     $result = Router::get(0, 'loc1');
     $this->assertIdentical($expected, $result);
     Router::scope('loc1', function () {
         Router::connect('/helloworld', array('controller' => 'Posts', 'action' => 'index'));
     });
     Router::scope('loc2', function () {
         Router::connect('/hello', array('controller' => 'Posts', 'action' => 'index'));
     });
     $this->assertCount(0, Router::get(null, true));
     $result = count(Router::get(null, 'loc1'));
     $this->assertCount(2, Router::get(null, 'loc1'));
     $scopes = Router::get();
     $result = 0;
     foreach ($scopes as $routes) {
         $result += count($routes);
     }
     $this->assertIdentical(3, $result);
 }