scope() 공개 정적인 메소드

Special use case: If $closure is not null executing the closure inside the specified scope.
public static scope ( string $name = null, Closure $closure = null ) : mixed
$name string Name of the scope to use.
$closure Closure A closure to execute inside the scope.
리턴 mixed Returns the previous scope if if `$name` is not null and `$closure` is null, returns the default used scope if `$name` is null, otherwise returns `null`.
예제 #1
0
 /**
  * Clean up after the test.
  */
 public function tearDown()
 {
     Router::reset();
     foreach ($this->_routes as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     unset($this->html);
 }
예제 #2
0
 protected function _restoreCtrlContext()
 {
     Router::reset();
     foreach ($this->_context['routes'] as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     foreach ($this->_context['scopes'] as $scope => $attachment) {
         Router::attach($scope, $attachment);
     }
     Router::scope($this->_context['scope']);
 }
예제 #3
0
 public function testMatchOverRequestParamsWithScope()
 {
     Router::scope('app1', function () {
         Router::connect('/hello/world1', 'HelloApp1::index');
     });
     Router::scope('app2', function () {
         Router::connect('/hello/world2', 'HelloApp2::index');
     });
     $request = new Request(array('url' => '/hello/world1'));
     $result = Router::process($request);
     $expected = array('controller' => 'HelloApp1', 'action' => 'index', 'library' => 'app1');
     $this->assertEqual($expected, $result->params);
     $result = Router::match($result->params);
     $this->assertEqual('/hello/world1', $result);
     $request = new Request(array('url' => '/hello/world2'));
     $result = Router::process($request);
     $expected = array('controller' => 'HelloApp2', 'action' => 'index', 'library' => 'app2');
     $this->assertEqual($expected, $result->params);
     $result = Router::match($result->params);
     $this->assertEqual('/hello/world2', $result);
 }
예제 #4
0
 public function testMatchWithScopeAndWithoutController()
 {
     Router::scope('app', function () {
         Router::connect('/{:id}', 'Posts::index');
     });
     $request = new Request(array('url' => '/1', 'base' => ''));
     MockDispatcher::run($request);
     $result = Router::match(array('id' => 2), $request);
     $this->assertEqual('/2', $result);
 }
예제 #5
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);
 }