solophp/contracts

Contracts and interfaces for Solo ecosystem

Installs: 80

Dependents: 7

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/solophp/contracts

v1.1.0 2025-12-04 20:41 UTC

This package is auto-updated.

Last update: 2025-12-04 20:42:02 UTC


README

Latest Version on Packagist License PHP Version

A collection of interfaces and contracts for the SoloPHP ecosystem. This package provides standardized contracts that enable interoperability between different SoloPHP components and allow developers to create custom implementations.

Requirements

  • PHP 8.1 or higher

Installation

Install the package via Composer:

composer require solophp/contracts

Available Contracts

Router

RouterInterface - Framework-agnostic interface for HTTP routing implementations.

use Solo\Contracts\Router\RouterInterface;

class MyRouter implements RouterInterface
{
    public function addRoute(string $method, string $path, $handler, array $options = []): void
    {
        // Your implementation
    }

    public function match(string $method, string $uri): array|false
    {
        // Your implementation
    }
}

Job Queue

JobInterface - Interface for executable job classes.

use Solo\Contracts\JobQueue\JobInterface;

class SendEmailJob implements JobInterface
{
    public function handle(): void
    {
        // Job execution logic
    }
}

JobQueueInterface - Interface for job queue implementations with support for scheduling, retries, and job processing.

use Solo\Contracts\JobQueue\JobQueueInterface;

class DatabaseJobQueue implements JobQueueInterface
{
    public function push(JobInterface $job, ?string $type = null, ?DateTimeImmutable $scheduledAt = null, ?DateTimeImmutable $expiresAt = null): int
    {
        // Add job to queue
    }

    // Implement other methods: addJob, getPendingJobs, processJobs, markCompleted, markFailed
}

Validator

ValidatorInterface - Interface for data validation implementations.

use Solo\Contracts\Validator\ValidatorInterface;

class MyValidator implements ValidatorInterface
{
    public function validate(array $data, array $rules, array $messages = []): array
    {
        // Validation logic
        return $errors; // Empty array if valid
    }
}

Container

WritableContainerInterface - Extends PSR-11 ContainerInterface with write capability for service registration.

use Solo\Contracts\Container\WritableContainerInterface;

class MyContainer implements WritableContainerInterface
{
    public function set(string $id, callable $factory): void
    {
        // Register service factory
    }

    public function get(string $id): mixed
    {
        // Retrieve service
    }

    public function has(string $id): bool
    {
        // Check if service exists
    }
}

Http

EmitterInterface - Interface for HTTP response emitters that send PSR-7 responses to the client.

use Solo\Contracts\Http\EmitterInterface;

class SapiEmitter implements EmitterInterface
{
    public function emit(ResponseInterface $response): void
    {
        // Emit headers and body to client
    }
}

Usage

{
    "require": {
        "solophp/contracts": "^1.0"
    }
}

Benefits

  • Interoperability - Components built on these contracts work together seamlessly
  • Flexibility - Swap implementations without changing dependent code
  • Type Safety - Strong typing ensures contract compliance
  • Framework Agnostic - Use in any PHP project

License

MIT