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

scope() public static method

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.
return 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`.
    public static function scope($name = null, \Closure $closure = null)
    {
        if ($name === null) {
            return static::$_scope;
        }
        if ($closure === null) {
            $former = static::$_scope;
            static::$_scope = $name;
            return $former;
        }
        $former = static::$_scope;
        static::$_scope = $name;
        call_user_func($closure);
        static::$_scope = $former;
    }

Usage Example

Beispiel #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);
 }
All Usage Examples Of lithium\net\http\Router::scope