phpdot / contracts
Shared interfaces for the PHPdot ecosystem
Requires
- php: >=8.5
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
README
Shared interfaces for the PHPdot ecosystem. Implementation packages implement these
interfaces; consumer packages type-hint against them. An implementation can be swapped
without changing any consumer code, and packages never depend on each other's internals.
Implementations live in the implementation packages; the only concrete classes here are
the pagination carriers (Paginator, CursorPaginator), because every implementation
must hand consumers the same wire-stable result shape.
Table of Contents
Requirements
| Requirement | Constraint |
|---|---|
| PHP | >= 8.5 |
psr/http-message |
^2.0 |
psr/http-server-handler |
^1.0 |
Installation
composer require phpdot/contracts
Usage
Consume a contract by type-hinting it:
use PHPdot\Contracts\Logs\WriterInterface; final readonly class AuditService { public function __construct( private WriterInterface $writer, ) {} }
Provide a contract by implementing it:
use PHPdot\Contracts\Logs\WriterInterface; final class StdoutWriter implements WriterInterface { public function write(array $record): void { fwrite(STDOUT, json_encode($record) . PHP_EOL); } }
Every interface documents its own contract rules (MUST/SHOULD semantics) on the methods they govern.
Testing
The package is standalone-testable:
composer install composer test # PHPUnit composer analyse # PHPStan, level max + strict rules composer check # Both, plus code style
License
MIT.
This repository is a read-only mirror, generated by CI from phpdot/monorepo. Pull requests and issues belong in the monorepo.