lithium\net\http\Media::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, Closur\Closure $closure = null ) : mixed
$name string Name of the scope to use.
$closure Closur\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
 public function testEmptyHostAndSchemeOptionLocation()
 {
     Media::attach('app', array('absolute' => true));
     Media::scope('app');
     $result = Media::asset('/js/path/file', 'js', array('base' => '/app/base'));
     $expected = 'http://localhost/app/base/js/path/file.js';
     $this->assertEqual($expected, $result);
 }
All Usage Examples Of lithium\net\http\Media::scope