Skip to content

Instantly share code, notes, and snippets.

@sword-jin
Created August 27, 2015 04:29
Show Gist options
  • Save sword-jin/448e552891b3c4683220 to your computer and use it in GitHub Desktop.
Save sword-jin/448e552891b3c4683220 to your computer and use it in GitHub Desktop.
Symfony Http-Component
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
// the URI being requested (e.g. /about) minus any query parameters
$request->getPathInfo();
// retrieve GET and POST variables respectively
$request->query->get('foo');
$request->request->get('bar', 'default value if bar does not exist');
// retrieve SERVER variables
$request->server->get('HTTP_HOST');
// retrieves an instance of UploadedFile identified by foo
$request->files->get('foo');
// retrieve a COOKIE value
$request->cookies->get('PHPSESSID');
// retrieve an HTTP request header, with normalized, lowercase keys
$request->headers->get('host');
$request->headers->get('content_type');
$request->getMethod(); // GET, POST, PUT, DELETE, HEAD
$request->getLanguages(); // an array of languages the client accepts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment