Download the PHP package philharmony/http-message without Composer
On this page you can find all versions of the php package philharmony/http-message. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download philharmony/http-message
More information about philharmony/http-message
Files in philharmony/http-message
Package http-message
Short Description PSR-7 HTTP message implementation with Enum typing for Philharmony
License MIT
Homepage https://github.com/philharmonytech/http-message
Informations about the package http-message
philharmony/http-message
Strict, type-safe PSR-7 HTTP Message implementation for modern PHP (8.1+). Designed for maximum security, immutability, and seamless integration with modern PHP 8.1+ ecosystems.
π Description
philharmony/http-message provides a robust, high-performance implementation of the PSR-7 HTTP Message interfaces. This package serves as the foundational messaging layer for the Philharmony framework, focusing on:
- Full PSR-7 Compliance β Interchangeable with any PSR-compliant library.
- Strict Typing β Verified with PHPStan Level 9 for rock-solid reliability.
- Security by Design β Prevents common URI vulnerabilities like path/host ambiguity (RFC 3986).
- Smart Encoding β Handles UTF-8 characters and avoids double-encoding of existing percent-encoded sequences.
- IPv6 & IDN Support β Fully supports IPv6 hosts and internationalized domain names.
- Enum Integration β Works natively with
philharmony/http-enumfor scheme and port logic. - Strict Validation β Prevents invalid hosts and illegal URI characters according to RFC 3986.
β¨ Key Features
- Full PSR-7 compliance β Fully compatible with the PHP ecosystem.
- Strict typing β Verified with PHPStan Level 9.
- Immutable design β Safe for middleware pipelines.
- IPv6 & IDN support β Modern host formats supported out of the box.
- Smart URI encoding β Prevents double-encoding and handles Unicode safely.
- Security-focused validation β Rejects invalid hosts and illegal URI characters.
- Upload error abstraction β PHP upload errors wrapped in a type-safe enum.
π‘ Why philharmony/http-message?
While many PSR-7 implementations focus on compatibility, philharmony/http-message focuses on:
- Maximum type safety through strict typing and PHPStan Level 9 analysis
- Security-first URI handling following RFC 3986
- Modern PHP support (8.1β8.4)
- Clean immutable design optimized for middleware architectures
π¦ Installation
Install via Composer:
β‘ Quick Start
A minimal example demonstrating the core PSR-7 objects provided by this package.
π Usage: URI
Creating a URI
IPv6 and IDN Hosts
The URI implementation supports modern host formats including IPv6 and internationalized domain names.
Immutability in Action
As per PSR-7, Uri objects are immutable. Every modification returns a new instance.
If the new value is identical to the current one, the same instance is returned for performance.
Advanced Encoding
The library automatically handles complex paths and query strings, ensuring they are RFC-compliant.
π Usage: Stream
The Stream class provides a type-safe wrapper around PHP resources (fopen, php://memory, etc.).
Polymorphic Creation
The static create() method is highly flexible and accepts strings, resources, or existing streams:
Direct File Creation
Use Stream::createFromFile() to create a stream directly from a file path. This method handles file opening and error management automatically:
Key benefits:
- Simplified creation β eliminates the need to manually call
fopen(); the method handles file opening internally. - Explicit error handling β throws
InvalidArgumentExceptionfor empty file names or modes, andRuntimeExceptionwith detailed error messages if the file cannot be opened (e.g., due to permission issues or nonβexistent paths). - Consistent interface β returns a
StreamInterfaceinstance, maintaining compatibility with otherStreamcreation methods likecreate(). - Input validation β performs basic validation of required parameters (
$fileNameand$modemust not be empty) before attempting file operations.
Safe Operations
Unlike raw PHP functions, Stream ensures that system errors are handled gracefully:
Predictable Stream Behaviour
The Stream implementation ensures consistent and predictable behavior across different stream types.
- Automatic rewind for string bodies β when creating a stream from a non-empty string, the pointer is automatically rewound.
- Reliable mode detection β readable and writable capabilities are detected based on the underlying stream mode.
- Safe string casting β
__toString()safely catches allThrowableerrors as required by PSR-7. - Robust size detection β stream size detection gracefully handles environments where
fstat()may return unexpected values.
These guarantees make the Stream implementation safe to use with memory streams, file streams, and custom PHP resources.
ποΈ Architecture: Base Message
All HTTP entities inherit from the abstract Message class, providing robust header management:
- Case-insensitive headers β withHeader('content-type', ...) and getHeader('Content-Type') work seamlessly.
- Protocol versioning β Supports HTTP/1.0, 1.1, 2.0.
- Immutable state β Every change produces a new instance, preventing side effects in middleware chains.
π Usage: HTTP Messages (Request & Response)
Philharmony provides full implementations of PSR-7 HTTP message types:
- Request β client-side HTTP request
- ServerRequest β server-side request containing environment data
- Response β HTTP response message
All messages extend the base Message abstraction and follow a fully immutable design.
Request (Client Request)
The Request class represents an outgoing HTTP request typically used by HTTP clients.
Creating a Request
Smart HTTP Method Helpers
Philharmony provides helper methods powered by the HttpMethod enum.
ServerRequest (Server-Side Request)
ServerRequest extends Request and represents an incoming HTTP request received by the server.
It provides access to additional environment data such as:
- server parameters (
$_SERVER) - cookies (
$_COOKIE) - query parameters (
$_GET) - uploaded files (
$_FILES) - parsed request bodies
Creating a ServerRequest
Parsed Body Helpers
The request body is automatically parsed depending on the Content-Type header.
Raw Body & Input Helpers
Convenience helpers allow retrieving input values from query parameters or parsed body data.
Lookup order:
- Query parameters
- Parsed request body
Response
The Response class automatically handles Reason Phrases using the Philharmony\Http\Enum\StatusCode.
π Usage: Uploaded Files
Handle file uploads with full PSR-7 compatibility and support for modern PHP features like full_path (PHP 8.1+).
Upload Error Handling
Upload errors are represented internally by the UploadError enum.
π Technical Specifications
| Feature | Implementation |
|---|---|
| PHP Version | 8.1 / 8.2 / 8.3 / 8.4 |
| PSR Standards | PSR-7 (HTTP Message Interfaces) |
| Static Analysis | PHPStan Level 9 (Max Strictness) |
| Code Quality | PSR-12, Strict Types, Clean Code |
| Dependencies | psr/http-message, philharmony/http-enum |
π§ͺ Testing
The package is strictly tested with PHPUnit 10 to ensure full compliance with HTTP standards and RFCs.
Run Tests
Code Coverage
ποΈ Static Analysis & Code Style
Verified with PHPStan Level 9 to ensure total type safety and prevent runtime errors.
Check and fix code style (PSR-12):
π License
This package is open-source and licensed under the MIT License. See the LICENSE file for details.
π€ Contributing
Contributions, issues, and feature requests are welcome.
If you find a bug or have an idea for improvement, please open an issue or submit a pull request.
β Support
If you find this package useful, please consider giving it a star on GitHub. It helps the project grow and reach more developers.
All versions of http-message with dependencies
philharmony/http-enum Version ^1.3
philharmony/http-psr-extension Version ^1.0
psr/http-message Version ^2.0.0