explaingit

symfony/http-foundation

8,636PHPAudience · developerComplexity · 2/5Setup · easy

TLDR

A PHP library that wraps HTTP requests and responses into clean objects, replacing PHP's scattered global variables with one structured way to read incoming data and build outgoing replies.

Mindmap

mindmap
  root((HttpFoundation))
    What it does
      HTTP request wrapper
      HTTP response builder
      Replaces superglobals
    Classes
      Request
      Response
      Cookie
      Session
      UploadedFile
    Tech
      PHP
      Symfony ecosystem
    Audience
      PHP developers
      Framework builders
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Read incoming query parameters, POST data, headers, and cookies from a single Request object instead of accessing PHP superglobals directly.

USE CASE 2

Build and send HTTP responses with status codes, headers, and body content using a Response object with a clean API.

USE CASE 3

Handle file uploads and session management in a PHP application using the structured classes this component provides.

Tech stack

PHPSymfony

Getting it running

Difficulty · easy Time to first run · 30min

Install via Composer, no external services required to start using the Request and Response classes.

In plain English

HttpFoundation is a PHP component from the Symfony project that wraps the HTTP request and response cycle in a set of PHP objects. HTTP is the protocol that web browsers and servers use to exchange data: a browser sends a request with information like a URL, headers, and optional form data, and the server sends back a response with a status code, headers, and the page content. In standard PHP, this information arrives as global variables and functions scattered across the language, such as the superglobal arrays for query string parameters and POST data, and separate header functions for controlling the response. HttpFoundation replaces that approach by providing a Request class that gathers all incoming data into one structured object, and a Response class for building and sending the reply in a controlled way. Related classes handle cookies, uploaded files, and sessions under the same structure. This is one of the foundational components of the Symfony web framework, but it is also distributed separately so other PHP projects can use it without adopting the full framework. Many PHP frameworks and tools depend on it directly. The README for this repository is minimal and primarily links to the full documentation and contribution guides on the Symfony website. Developers looking for usage examples and detailed API documentation should visit those links rather than the README itself. The component targets PHP developers building web applications who want a cleaner, more structured way to handle HTTP requests and responses.

Copy-paste prompts

Prompt 1
Using Symfony HttpFoundation, write me a PHP script that reads a query parameter called 'username' from the request, validates it is not empty, and returns a JSON response with a 400 status if it is missing.
Prompt 2
Show me how to set a cookie on an HttpFoundation Response object, including the expiry time and the httpOnly flag.
Prompt 3
I am building a PHP app without the full Symfony framework. How do I install only the HttpFoundation component via Composer and create a Request object from the current browser request?
Prompt 4
Using HttpFoundation's Session class, write me code that stores a user ID in a session after login and retrieves it on the next request to check if the user is authenticated.
Prompt 5
How do I handle a file upload with Symfony HttpFoundation? Show me how to get the uploaded file from the Request object, check its MIME type, and move it to a storage directory.
Open on GitHub → Explain another repo

← symfony on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.