Skip to content

rkrx/php-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 

Repository files navigation

PHP Contracts

A curated list of PHP contract packages: small, stable interfaces that define how two pieces of code work together without forcing either side to depend on one concrete implementation.

Contracts are most useful at the boundaries of an application. A package can depend on an HTTP client contract such as PSR-18 instead of depending directly on Guzzle, Symfony HttpClient or any other client. The application can then choose the implementation, swap it later, mock it in tests, or share code across frameworks with less friction.

This repository collects interface packages that are worth considering when designing those boundaries. It is not a list of every abstraction in the PHP ecosystem. The focus is on contracts that are documented, mature enough for real projects, and supported by practical implementations.

Guidelines:

  1. The package must define a clear contract through one or more PHP interfaces.
  2. The contract must describe behavior and expectations, not the internals of a specific implementation.
  3. The interfaces must be usable without requiring a particular framework, service container or runtime.
  4. Implementations may exist in the same ecosystem, but user code should be able to depend on the contract package alone.
  5. The project must provide useful English documentation, including the purpose of the contract and the expectations for implementers.
  6. The interfaces must comply with PSR-1 and should comply with PSR-12.
  7. There should be real implementations or adapters that demonstrate the practical value of the contract.
  8. The package should be available through Packagist and follow normal Composer versioning practices.

Stable

(Click on an item to get a list of available implementations)

Project Latest Implementations
Logger Interface (PSR-03) Latest Stable Compatible Packages
Simple Cache (PSR-16) Latest Stable Compatible Packages
Caching Interface (PSR-06) Latest Stable Compatible Packages
Container Interface (PSR-11) Latest Stable Compatible Packages
HTTP Message Interface (PSR-07) Latest Stable Compatible Packages
HTTP-Client (PSR-18) Latest Stable Compatible Packages
HTTP Server-Handler (PSR-15) Latest Stable Compatible Packages
HTTP Server-Middleware (PSR-15) Latest Stable Compatible Packages
HTTP Factories (PSR-17) Latest Stable Compatible Packages
Hypermedia Links (PSR-13) Latest Stable Compatible Packages
Event Dispatcher (PSR-14) Latest Stable Compatible Packages
Clock (PSR-20) Latest Stable Compatible Packages

Contract-oriented packages

Not every useful PHP contract is a PSR. The following packages are still useful when their domain matches an application boundary, because they publish interfaces separately from implementations or are mostly contract packages.

Project Latest Focus Implementations / Notes
Symfony Cache Contracts Latest Stable Cache access with Symfony's cache semantics on top of PSR-6/PSR-16. Compatible Packages
Symfony Event Dispatcher Contracts Latest Stable Event dispatching contract compatible with Symfony components and PSR-14. Compatible Packages
Symfony HTTP Client Contracts Latest Stable HTTP client contract for synchronous, asynchronous and streaming HTTP clients. Compatible Packages
Symfony Service Contracts Latest Stable Service and dependency-injection contracts built around PSR-11. Compatible Packages
Symfony Translation Contracts Latest Stable Translation interfaces for framework-independent internationalization boundaries. Compatible Packages
HTTPlug Latest Stable HTTP client abstraction built on PSR-7, especially useful for asynchronous clients. Compatible Packages; prefer PSR-18 for purely synchronous HTTP clients.
Doctrine Persistence Latest Stable Shared persistence interfaces and base contracts for Doctrine object mappers. Useful at Doctrine-style persistence boundaries, not as a general repository standard.
Illuminate Contracts Latest Stable Broad Laravel ecosystem contracts for cache, container, events, queues, routing and more. Best suited for Laravel-compatible packages and applications.

Noteworthy projects

  • HttpKernelInterface – HttpKernelInterface handles a Request to convert it to a Response.
  • FlySystem – Flysystem is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one. Reducing technical debt and chance of vendor lock-in.

Wishlist

  • 3rd Party APIs (Amazon, Google etc)
  • Authentication
  • (More) Communication (Email, Sms, Notifications etc.)
  • (More) Date-, Time-, Interval-, Calendar-Manipulation
  • (More) Dependency-Injection-Container interfaces with more methods (make, call etc.)
  • E-Commerce (Payment, common order structures, common address structures etc.)
  • FileSystem-Abstraction
  • Filetype-Abstraction
  • Filtering
  • Image-Manipulation
  • Key-Value-Stores
  • ORM / Data-Handling / Data-Structures
  • Queues (like RabbitMQ / Gearman)
  • Search-Server-Interfaces (querying, Responses, Facettes etc)
  • Template-Engines
  • URL-Manipulation
  • Validation

About

A curated list of mature interfaces to build components on

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors