Skip to content

Contract

Contract is a dependency free package of PHP interfaces that every other Raxos package implements or type hints against. It lets packages refer to each other's behavior without depending on each other's concrete classes, so modules stay decoupled, testable and swappable. It holds only interfaces, no concrete logic, and because it has no Raxos dependencies of its own it sits at the very bottom of the dependency graph and is safe to require from anywhere, including your own application code.

Its namespaces mirror the packages it describes. Raxos\Contract\Database describes raxos/database, Raxos\Contract\Router describes raxos/router, and so on. On top of those, a small set of root level interfaces (ExceptionInterface, DebuggableInterface, SerializableInterface) is shared by every package.

Highlights

Explore by category

  • Package organization: how the interfaces are grouped by namespace so you can find the contract for a given package quickly.
  • Exception contracts: the shared exception interface hierarchy rooted in ExceptionInterface, the part of the package application code touches most often.
  • Extension points: the interfaces you implement yourself to plug custom behavior into a Raxos package.

Quick example

Type hint against a contract rather than a concrete class, so the implementation can be swapped or mocked without touching your code.

php
<?php
declare(strict_types=1);

use Raxos\Contract\Container\ContainerInterface;

final readonly class ReportService
{
    public function __construct(
        private ContainerInterface $container,
    ) {}

    public function build(string $abstract): object
    {
        return $this->container->get($abstract);
    }
}

Installation

Install the package with Composer and check the requirements on the installation page.

shell
composer require raxos/contract