aeruz/app-registry-bundle
Laravel bundle that provides an application registry: register apps/services, store metadata and configuration, and expose lookup/management utilities for integrations and multi-app environments. Useful for keeping app definitions centralized and discoverable across your system.
Installation Add the bundle via Composer:
composer require aeruz/app-registry-bundle
Enable it in config/bundles.php:
Aeruz\AppRegistryBundle\AppRegistryBundle::class => ['all' => true],
First Use Case: Registering an Application
Define an application in config/packages/app_registry.yaml:
aeruz_app_registry:
applications:
my_app:
name: "My Application"
enabled: true
routes: ["app_*"]
middleware: ["auth", "locale"]
Accessing the Registry
Inject the AppRegistry service in a controller or service:
use Aeruz\AppRegistryBundle\Registry\AppRegistry;
public function __construct(private AppRegistry $registry) {}
public function checkApp(): void
{
$app = $this->registry->get('my_app');
if ($app) {
// Application is registered and enabled
}
}
Routing Integration
Use the app_registry extra in your routes (config/routes.yaml):
app_home:
path: /
controller: App\Controller\HomeController::index
app_registry: my_app
Dynamic Application Switching
Use the AppRegistry to conditionally load services, routes, or middleware based on the active application:
$activeApp = $this->registry->getActiveApp();
if ($activeApp->hasMiddleware('auth')) {
$this->addMiddleware($activeApp->getMiddleware('auth'));
}
Service Provider Isolation
Extend the bundle’s AppRegistryServiceProvider to bind application-specific services:
use Aeruz\AppRegistryBundle\DependencyInjection\AppRegistryExtension;
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services/my_app.yaml');
}
Event-Driven Extensions
Listen to AppRegistryEvents (e.g., AppRegisteredEvent) to react to application lifecycle changes:
$dispatcher->addListener(AppRegistryEvents::APP_REGISTERED, function (AppRegisteredEvent $event) {
$this->logger->info(sprintf('Registered app: %s', $event->getApp()->getName()));
});
{% if app_registry.activeApp %}
<div class="app-header">{{ app_registry.activeApp.name }}</div>
{% endif %}
# config/api_platform/resources.yaml
resources:
App\Entity\Post:
app_registry: my_app
operations:
- GET
- POST
Circular Dependencies
Avoid circular references between applications (e.g., app_a requiring app_b, which in turn requires app_a). Use lazy-loading or interfaces to decouple dependencies.
Middleware Ordering
Middleware defined in the registry runs after global middleware. Override the kernel.middleware config if ordering is critical:
# config/packages/framework.yaml
framework:
middleware: ['app_registry_middleware', 'other_middleware']
Route Precedence
Routes with app_registry take precedence over global routes only if the application is active. Test with:
php bin/console debug:router | grep "app_registry"
php bin/console debug:app-registry
# config/packages/dev/framework.yaml
framework:
router:
debug: "%kernel.debug%"
profiler: { only_exceptions: false }
Custom Application Classes
Extend Aeruz\AppRegistryBundle\Model\App to add metadata:
namespace App\Model;
use Aeruz\AppRegistryBundle\Model\App as BaseApp;
class App extends BaseApp
{
public function getIcon(): string
{
return $this->getOption('icon', 'default_icon');
}
}
Register the custom class in config/packages/app_registry.yaml:
aeruz_app_registry:
app_class: App\Model\App
Dynamic Application Loading
Implement Aeruz\AppRegistryBundle\Loader\AppLoaderInterface to load applications from a database or external API:
class DatabaseAppLoader implements AppLoaderInterface
{
public function load(): array
{
return $this->db->fetchAll('SELECT * FROM applications');
}
}
Bind it in services.yaml:
services:
Aeruz\AppRegistryBundle\Loader\AppLoaderInterface: '@App\Loader\DatabaseAppLoader'
Conditional Application Activation
Override AppRegistry::getActiveApp() to implement custom logic (e.g., subdomain-based activation):
public function getActiveApp(): ?App
{
$subdomain = $this->requestStack->getMainRequest()->getHost();
return $this->apps->get($subdomain);
}
How can I help you explore Laravel packages today?