sylius/registry
Sylius Registry component provides a simple service registry to store, retrieve, and manage services by type and name. Useful for decoupling implementations, selecting handlers at runtime, and organizing extensible systems in Symfony/Laravel-style PHP apps.
sylius/registry package implements a type-safe service registry that aligns with Laravel’s dependency injection (DI) principles but offers runtime flexibility for dynamic service resolution. This is particularly useful in Laravel for:
Illuminate\Container handles static service binding, this package excels in interface-constrained, key-based dynamic resolution, reducing boilerplate for plugin-like systems.ContainerInterface) for simple use cases.$this->app->singleton('payment.registry', fn() =>
new ServiceRegistry(PaymentGatewayInterface::class)
);
when() conditions or tagged services.autowire: true equivalent).all() Method: Returns a new array copy on each call, which could be inefficient for large registries (>1000 entries).get('stripe') where 'stripe' is a runtime key)?Macroable container, League\Container, or custom implementations)?all() could become a bottleneck.StripeGateway with a mock)?PaymentGatewayInterface objects)?app()->bindWhen(), app()->tag()) replace this with minimal refactoring?use Sylius\Component\Registry\ServiceRegistry;
$this->app->singleton('payment.gateways', fn() =>
new ServiceRegistry(PaymentGatewayInterface::class)
);
// app/Providers/RegistryServiceProvider.php
public function register()
{
$this->app->bind('payment.gateways', fn() =>
new ServiceRegistry(PaymentGatewayInterface::class)
);
}
// app/Facades/PaymentGatewayRegistry.php
public static function get($key)
{
return app('payment.gateways')->get($key);
}
composer require vendor/plugin).config('services.payment')).ServiceProvider.// Register a service
app('payment.gateways')->register('stripe', new StripeGateway());
// Retrieve via facade
$gateway = PaymentGatewayRegistry::get('stripe');
all() results).'cache' as a registry key).Illuminate\Contracts\*).all() or prioritized registries become bottlenecks.PaymentGatewayInterface object.all() to consume excessive memory.security@sylius.com.How can I help you explore Laravel packages today?