Installation
composer require commongateway/corebundle
Add the bundle to config/bundles.php in Symfony:
return [
// ...
CommonGateway\CoreBundle\CommonGatewayCoreBundle::class => ['all' => true],
];
Basic Configuration
Create a config/packages/commongateway.yaml file:
commongateway:
plugins_dir: "%kernel.project_dir%/var/plugins"
default_plugin: "base_plugin"
First Plugin Setup
plugins/base_plugin/installation.json:
{
"name": "Base Plugin",
"version": "1.0.0",
"endpoints": [
{
"path": "/api/data",
"methods": ["GET"],
"handler": "App\\Plugin\\DataHandler"
}
]
}
src/Plugin/DataHandler.php):
namespace App\Plugin;
use CommonGateway\CoreBundle\Plugin\AbstractHandler;
class DataHandler extends AbstractHandler
{
public function handleGet(): array
{
return ['data' => 'Hello, Common Gateway!'];
}
}
Register Plugin Run the installation service to register the plugin:
php bin/console commongateway:install-plugin base_plugin
Test the Endpoint Access the endpoint via HTTP:
curl http://localhost:8000/api/data
src/Resources/doc/ for bundle-specific docs.config/packages/commongateway.yaml for available options.var/plugins/ for example plugin layouts.php bin/console list commongateway to explore CLI tools.Plugin Structure
installation.json: Defines metadata, endpoints, and dependencies.
{
"name": "MyPlugin",
"version": "1.0.0",
"endpoints": [
{
"path": "/custom/endpoint",
"methods": ["POST"],
"handler": "App\\Plugin\\CustomHandler",
"middleware": ["auth", "validate"]
}
],
"dependencies": ["base_plugin"]
}
AbstractHandler and implement methods for HTTP verbs (handleGet, handlePost, etc.).
class CustomHandler extends AbstractHandler
{
public function handlePost(array $data): array
{
// Process data, validate, and return response
return $this->json(['status' => 'success']);
}
}
Middleware Integration Use middleware for cross-cutting concerns (e.g., auth, logging):
# config/packages/commongateway.yaml
commongateway:
middleware:
auth: App\Middleware\AuthMiddleware
validate: App\Middleware\ValidationMiddleware
Dynamic Schema Generation
Leverage the InstallationService to auto-generate database schemas from plugin definitions:
php bin/console commongateway:generate-schema my_plugin
RBAC Integration
Define roles and permissions in installation.json:
{
"roles": {
"admin": ["create", "read", "update", "delete"],
"user": ["read"]
}
}
Use the AuthorizationChecker in handlers:
if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
}
Symfony-Laravel Bridge
Use symfony/bridge to integrate Symfony bundles with Laravel:
composer require symfony/bridge
Configure Laravel’s service provider to load the bundle:
// config/app.php
'providers' => [
// ...
Symfony\Component\HttpKernel\HttpKernelBundle\HttpKernelBundle::class,
CommonGateway\CoreBundle\CommonGatewayCoreBundle::class,
],
Routing Extend Laravel’s router to include Common Gateway endpoints:
// routes/web.php
Route::get('/api/data', function () {
return app(\CommonGateway\CoreBundle\Gateway::class)->handleRequest();
});
Service Container Bind Symfony services to Laravel’s container:
$app->singleton(\CommonGateway\CoreBundle\InstallationService::class, function ($app) {
return new \CommonGateway\CoreBundle\InstallationService(
$app->make('config'),
$app->make('filesystem')
);
});
Event Listeners
Subscribe to Common Gateway events (e.g., PluginInstalledEvent):
// EventSubscriber
class PluginEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'commongateway.plugin.installed' => 'onPluginInstalled',
];
}
public function onPluginInstalled(PluginInstalledEvent $event)
{
// Log or trigger Laravel events
event(new \App\Events\PluginInstalled($event->getPlugin()));
}
}
Plugin Dependency Hell
dependencies in installation.json and validate with:
php bin/console commongateway:validate-plugins
Handler Naming Collisions
MyPlugin\DataHandler).Middleware Order Matters
installation.json:
{
"endpoints": [
{
"middleware": ["validate", "auth"]
}
]
}
Caching Headaches
php bin/console cache:clear
php bin/console commongateway:clear-cache
RBAC Misconfigurations
php bin/console commongateway:check-permissions admin /api/data
Enable Verbose Logging
# config/packages/commongateway.yaml
commongateway:
debug: true
Check logs at var/log/commongateway.log.
Dump Plugin Metadata
php bin/console commongateway:debug-plugin base_plugin
Test Endpoints Locally Use Symfony’s built-in server for testing:
php bin/console server:run
Validate JSON Schemas
Ensure installation.json is valid JSON:
php bin/console commongateway:validate-json plugins/base_plugin/installation.json
Custom Installation Logic
Extend the InstallationService to add pre/post-install hooks:
class CustomInstallationService extends \CommonGateway\CoreBundle\InstallationService
{
protected function postInstall(Plugin $plugin)
{
// Custom logic (e.g., send notification)
}
}
Bind it in services:
services:
CommonGateway\CoreBundle\InstallationService:
class: App\Service\CustomInstallationService
Dynamic Endpoint Routing Override the router to add dynamic routes:
// src/CommonGateway/CoreBundle/DependencyInjection/Compiler/Pass.php
public function process(ContainerBuilder $container)
{
$definition = $container->findDefinition('router');
$definition->addMethodCall('addDynamicRoutes', [
$container->getParameter('commongateway.endpoints')
]);
}
Plugin Marketplace
Build a marketplace for plugins by extending the PluginRepository:
class MarketplacePluginRepository extends \CommonGateway\CoreBundle\Plugin\PluginRepository
{
public function fetchFromMarketplace(string $pluginName): Plugin
{
// Fetch and install from remote source
}
}
Webhook Support
Add webhook endpoints by extending the Gateway class:
class WebhookGateway extends \CommonGateway\CoreBundle\Gateway
{
public function handleWebhook(array $payload): array
{
// Process webhook payload
}
}
How can I help you explore Laravel packages today?