Purl\Url::fromCurrent PHP Метод

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

Creates an Url instance based on data available on $_SERVER variable.
public static fromCurrent ( ) : Url
Результат Url
    public static function fromCurrent()
    {
        $scheme = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http';
        $host = $_SERVER['HTTP_HOST'];
        $baseUrl = "{$scheme}://{$host}";
        $url = new self($baseUrl);
        if (!empty($_SERVER['REQUEST_URI'])) {
            if (strpos($_SERVER['REQUEST_URI'], '?') !== false) {
                list($path, $query) = explode('?', $_SERVER['REQUEST_URI'], 2);
            } else {
                $path = $_SERVER['REQUEST_URI'];
                $query = '';
            }
            $url->set('path', $path);
            $url->set('query', $query);
        }
        // Only set port if different from default (80 or 443)
        if (!empty($_SERVER['SERVER_PORT'])) {
            $port = $_SERVER['SERVER_PORT'];
            if ($scheme == 'http' && $port != 80 || $scheme == 'https' && $port != 443) {
                $url->set('port', $port);
            }
        }
        // Authentication
        if (!empty($_SERVER['PHP_AUTH_USER'])) {
            $url->set('user', $_SERVER['PHP_AUTH_USER']);
            if (!empty($_SERVER['PHP_AUTH_PW'])) {
                $url->set('pass', $_SERVER['PHP_AUTH_PW']);
            }
        }
        return $url;
    }

Usage Example

Пример #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
All Usage Examples Of Purl\Url::fromCurrent