phprise / http-value-object
Atomic Repository for Value Object of HTTP Connector based on the OTAKU Manifesto.
Installs: 3
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:project
pkg:composer/phprise/http-value-object
Requires
- php: ^8.4
- phprise/common: ^2.0
- phprise/data-transfer-object: ^1.1
- phprise/http-contract: ^1.0
- psr/http-message: ^2.0
Requires (Dev)
- phpunit/phpunit: ^12.5
- vimeo/psalm: ^6.14
README
The Atomic Repository is the smallest possible unit of granularity. It enforces a strict architectural boundary through the following rules:
- No Subdirectories: Only one level of directory inside src/.
- Maximum 10 Files: Only 10 files per package.
- Strict Typing: Mandatory
declare(strict_types=1)and full type hinting for all properties and methods. - Object Calisthenics: Maximum of 50 lines per class and 2 instance variables to ensure extreme cohesion.
- Value Objects: All primitives must be wrapped. Raw strings or integers are not permitted in domain logic.
- First Class Collections: Arrays are forbidden for data transport; use dedicated Collection objects.
- Tell, Don't Ask: Getters and setters are prohibited. Objects must expose behavior, not state.
- Infrastructure Ignorance: The domain core is decoupled from persistence, frameworks, and external tools.
- Logic Flow: The
elsekeyword is banned. Use guard clauses and early returns to minimize indentation.
Installation
Install the package via Composer:
composer require phprise/http-value-object
Usage
This repository provides fundamental HTTP value objects. It is an Atom, designed to be immutable, strictly typed, and free of complex business logic.
Headers
Headers are handled strictly. All names are normalized to lowercase.
use Phprise\Http\ValueObject\Headers; $headers = new Headers([ 'Content-Type' => ['application/json'] ]); // Immutably add a header $newHeaders = $headers->with('Authorization', 'Bearer token'); if ($newHeaders->has('authorization')) { $values = $newHeaders->get('authorization'); } $array = $newHeaders->toArray();
Uri
A robust implementation of Psr\Http\Message\UriInterface.
use Phprise\Http\ValueObject\Uri; $uri = new Uri('https://api.example.com/v1/users?query=otaku'); echo $uri->getHost(); // api.example.com echo $uri->getPath(); // /v1/users // Immutably change the path $newUri = $uri->withPath('/v2/users');
Tip
This atom is meant to be split into even smaller units as the system evolves, ensuring that each component contains zero complex logic and serves only as a structured data container.
Available Components
- Headers: Immutable collection of HTTP headers with normalization.
- Uri: Robust PSR-7 compliant URI implementation.
- Streams:
NativeStream,JsonStream, andEmptyStreamfor payload handling. - NativeResponse: Simple wrapper for native PHP response handling.
- RequestContext: Value object to encapsulate HTTP request metadata.
Philosophy
We follow The OTAKU Manifesto: Fluid Structure Design.
- O - Own your Discipline (Be strict with yourself)
- T - Tools for Composition (Compose like Unix)
- A - Armor the Core (Protect the heart of the business)
- K - Keep Infrastructure Silent (Infrastructure is just a detail)
- U - Universal Language & Contracts (Speak the user's language via clear contracts)
Please read more about it in PHILOSOPHY.md.
License
MIT License
Free to use, modify, and distribute.