fromCurrent() публичный статический Метод

Creates an Url instance based on data available on $_SERVER variable.
public static fromCurrent ( ) : Url
Результат Url
Пример #1
0
}
// Add database configuration to config array
$config->add($dbConfig);
/**
 * Start Request Response Objects
 */
$request = function () {
    return \Sabre\HTTP\Sapi::getRequest();
};
$response = function () {
    return new \Sabre\HTTP\Response();
};
/**
 * Start url parser
 */
$url = \Purl\Url::fromCurrent();
// determine if we are on https or not
$ssl = $url['port'] == '443' ? true : false;
/**
 * Start dic container
 */
$dic = new \Auryn\Injector();
// Share object instances
$services = [$config, $db, $mail(), $request(), $response(), $time(), $url];
foreach ($services as $service) {
    $dic->share($service);
}
//check if user is a robot
$robots = (require_once __DIR__ . '/Config/' . ENVIRONMENT . '/Robots.php');
/**
 * Start user object
Пример #2
0
 public function testFromCurrentServerVariables()
 {
     $_SERVER['HTTP_HOST'] = 'jwage.com';
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['REQUEST_URI'] = '/about';
     $url = Url::fromCurrent();
     $this->assertEquals('http://jwage.com/about', (string) $url);
     $_SERVER['REQUEST_URI'] = '/about?param=value';
     $url = Url::fromCurrent();
     $this->assertEquals('http://jwage.com/about?param=value', (string) $url);
     $_SERVER['HTTPS'] = 'off';
     $_SERVER['HTTP_HOST'] = 'jwage.com';
     unset($_SERVER['SERVER_PORT']);
     unset($_SERVER['REQUEST_URI']);
     $url = Url::fromCurrent();
     $this->assertEquals('http://jwage.com/', (string) $url);
     $_SERVER['HTTPS'] = 'on';
     $_SERVER['HTTP_HOST'] = 'jwage.com';
     $_SERVER['SERVER_PORT'] = 443;
     unset($_SERVER['REQUEST_URI']);
     $url = Url::fromCurrent();
     $this->assertEquals('https://jwage.com/', (string) $url);
     unset($_SERVER['HTTPS']);
     $_SERVER['HTTP_HOST'] = 'jwage.com';
     $_SERVER['SERVER_PORT'] = 8080;
     unset($_SERVER['REQUEST_URI']);
     $url = Url::fromCurrent();
     $this->assertEquals('http://jwage.com:8080/', (string) $url);
     unset($_SERVER['HTTPS']);
     $_SERVER['HTTP_HOST'] = 'jwage.com';
     $_SERVER['SERVER_PORT'] = 80;
     unset($_SERVER['REQUEST_URI']);
     $_SERVER['PHP_AUTH_USER'] = '******';
     $_SERVER['PHP_AUTH_PW'] = 'passwd123';
     $url = Url::fromCurrent();
     $this->assertEquals('http://*****:*****@jwage.com/', (string) $url);
 }