Skip to content

Instantly share code, notes, and snippets.

@chriseskow
Created October 7, 2015 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseskow/2711290009738004f6e7 to your computer and use it in GitHub Desktop.
Save chriseskow/2711290009738004f6e7 to your computer and use it in GitHub Desktop.
<?php
/*
composer.json:
{
"require": {
"slim/slim": "^3.0@RC",
"zendframework/zend-diactoros": "^1.1",
"symfony/http-foundation": "^2.7"
}
}
*/
require 'vendor/autoload.php';
function test($message, $value) {
printf("%-35s%s\n", $message, $value);
}
test('$_SERVER["REQUEST_URI"]', $_SERVER['REQUEST_URI']);
test('$_SERVER["SCRIPT_NAME"]', $_SERVER['SCRIPT_NAME']);
test('$_SERVER["PATH_INFO"]', $_SERVER['PATH_INFO']);
test('$_SERVER["PHP_SELF"]', $_SERVER['PHP_SELF']);
$e = new Slim\Http\Environment($_SERVER);
$r = Slim\Http\Request::createFromEnvironment($e);
test('Slim getBasePath()', $r->getUri()->getBasePath());
test('Slim getPath()', $r->getUri()->getPath());
$r = Zend\Diactoros\ServerRequestFactory::fromGlobals();
test('Diactoros getPath()', $r->getUri()->getPath());
$r = Symfony\Component\HttpFoundation\Request::createFromGlobals();
test('HttpFoundation getRequestUri()', $r->getRequestUri());
test('HttpFoundation getScriptName()', $r->getScriptName());
test('HttpFoundation getPathInfo()', $r->getPathInfo());
test('HttpFoundation getBasePath()', $r->getBasePath());
test('HttpFoundation getBaseUrl()', $r->getBaseUrl());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment