📦 Marketplace⭐ GitHub
Packagesv1.0

Contracts

License: MIT

Lightweight contracts (interfaces & abstract base classes) for the MonkeysLegion framework.

This package exists so that external packages and third-party bundles can implement framework contracts (like ServiceProviderInterface) without pulling in the entire monkeyscloud/monkeyslegion meta-package.

Installation

composer require monkeyscloud/monkeyslegion-contracts

Dependencies

PackageVersion
php^8.4
psr/container^2.0

That's it. No framework packages required.

Provided Contracts

ServiceProviderInterface

The contract for modular service providers. Implement this to register DI definitions, specify context (http, cli, all), and hook into the container boot lifecycle.

use MonkeysLegion\Contracts\ServiceProviderInterface;
use Psr\Container\ContainerInterface;

class MyPackageProvider implements ServiceProviderInterface
{
    public function getDefinitions(): array
    {
        return [
            MyService::class => fn() => new MyService(),
        ];
    }

    public function provides(): array
    {
        return [MyService::class];
    }

    public function context(): string
    {
        return 'all';
    }

    public function isDeferred(): bool
    {
        return false;
    }

    public function boot(ContainerInterface $container): void
    {
        // Post-build initialization
    }
}

AbstractServiceProvider

Convenience base class with sensible defaults — only getDefinitions() is required:

use MonkeysLegion\Contracts\AbstractServiceProvider;

class MyPackageProvider extends AbstractServiceProvider
{
    public function getDefinitions(): array
    {
        return [
            MyService::class => fn() => new MyService(),
        ];
    }
}

How It Fits Together

LayerPackageWhat it does
Contractmonkeyslegion-contractsDefines ServiceProviderInterface
FrameworkmonkeyslegionDiscovers & boots providers via ProviderScanner
Your Packageyour-vendor/your-packageImplements the interface, requires only contracts
Appmonkeyslegion-skeletonRegisters package providers in Bootstrap

External packages require only monkeyslegion-contracts. The consuming application registers them during bootstrap:

Application::create($basePath)
    ->withProviders([YourPackageProvider::class])
    ->run();

License

MIT © MonkeysCloud