Installation Run in your Symfony project root:
composer require common-gateway/bag-bundle:dev-main
For Dockerized environments:
docker-compose exec php composer require common-gateway/bag-bundle:dev-main
Enable the Bundle
Add to config/bundles.php:
CommonGateway\BagBundle\CommonGatewayBagBundle::class => ['all' => true],
Install Entities (if applicable) Execute the installation command:
php bin/console commongateway:install common-gateway/bag-bundle
Or in Docker:
docker-compose exec php bin/console commongateway:install common-gateway/bag-bundle
Verify Installation
Check the config/packages/common_gateway_bag.yaml for generated configuration or inspect the src/Entity directory for new models.
Use this package as a template to scaffold a new Symfony Flex bundle. Follow these steps:
CommonGateway\BagBundle namespace with your own (e.g., YourVendor\YourBundle).
Update composer.json metadata (name, description, etc.).src/Resources/config/services.yaml to register your services.
Add custom entities in src/Entity/ and update src/DependencyInjection/Configuration.php for bundle configuration.Scaffold the Bundle Clone the generated template repo and replace placeholders with your logic. Example structure:
src/
├── Controller/ # Custom controllers (e.g., ApiController.php)
├── Entity/ # Doctrine entities (e.g., YourEntity.php)
├── Repository/ # Custom repositories
├── Resources/
│ ├── config/ # Services, routes, doctrine
│ ├── public/ # Static assets
│ └── views/ # Twig templates (if applicable)
└── DependencyInjection/
├── Configuration.php # Bundle config schema
└── YourBundleExtension.php # Config loader
Integrate with Symfony
src/Resources/config/services.yaml and tag them for autowiring.
services:
YourVendor\YourBundle\Service\YourService:
arguments:
- '@doctrine.orm.entity_manager'
config/routes/your_bundle.yaml) or annotations.
your_bundle_homepage:
path: /your-bundle
controller: YourVendor\YourBundle\Controller\YourController::index
src/Entity/BaseEntity.php (if provided) or create standalone entities with lifecycle callbacks.
namespace YourVendor\YourBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class YourEntity extends BaseEntity {
#[ORM\Column]
private string $name;
}
Configuration
Extend src/DependencyInjection/Configuration.php to add custom parameters:
$rootNode
->children()
->scalarNode('default_setting')
->defaultValue('default')
->end()
->end();
Access in controllers/services via:
$this->container->getParameter('your_bundle.default_setting');
Commands
Add custom console commands in src/Command/ and register them in services.yaml:
services:
YourVendor\YourBundle\Command\YourCommand:
tags: ['console.command']
Testing
Use Symfony’s TestCase and KernelTestCase to test controllers, services, and commands.
Example:
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class YourControllerTest extends WebTestCase {
public function testIndex() {
$client = static::createClient();
$client->request('GET', '/your-bundle');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
}
php bin/console make:migration
php bin/console doctrine:migrations:migrate
# config/bundles.php
YourVendor\YourBundle\YourBundle::class => ['all' => true],
Create a resources/stimulus or resources/webpack folder for frontend assets.KernelEvents::REQUEST) in services.yaml:
services:
YourVendor\YourBundle\EventListener\YourListener:
tags:
- { name: 'kernel.event_listener', event: 'kernel.request', method: 'onKernelRequest' }
src/Entity/YourEntity.php with API resources:
use ApiPlatform\Metadata\ApiResource;
#[ApiResource]
class YourEntity extends BaseEntity { ... }
Namespace Collisions
YourVendor\YourBundle) is unique to avoid conflicts with other bundles.composer.json under autoload.psr-4.Missing Configuration
commongateway:install fails, verify:
config/bundles.php.CommonGateway\BagBundle namespace is replaced with your bundle’s namespace in all files.php bin/console debug:container | grep your_bundle
Doctrine Entity Issues
php bin/console cache:clear
src/Entity/ is in your autoload-dev.psr-4 in composer.json:
"autoload-dev": {
"psr-4": {
"YourVendor\\YourBundle\\": "src/"
}
}
Command Not Found
commongateway:install is missing, ensure the bundle’s Command/ directory is properly registered in services.yaml:
services:
YourVendor\YourBundle\Command\InstallCommand:
tags: ['console.command']
Flex Recipe Conflicts
composer.json includes a replace or conflict section to avoid version clashes:
"replace": {
"symfony/framework-bundle": "^5.4"
}
Log Bundle Activation Add a debug listener to verify bundle loading:
// src/DependencyInjection/YourBundleExtension.php
public function load(array $configs, ContainerConfigurator $container) {
$container->parameters()->set('your_bundle.debug', true);
}
Check logs:
php bin/console debug:config your_bundle
Dump Services Inspect registered services:
php bin/console debug:container YourVendor\YourBundle
Doctrine Debugging
Enable SQL logging in .env:
DOCTRINE_DDL_AUTO_CREATE_SCHEMA=true
DOCTRINE_DDL_AUTO_CREATE_SCHEMA_SAFE_CHARSET=true
DOCTRINE_DDL_AUTO_CREATE_SCHEMA_SAFE_COLLATE=true
View queries:
php bin/console debug:query
Custom Console Commands
Extend the commongateway:install command by creating a new command that calls the original:
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CustomInstallCommand extends Command {
protected function execute(InputInterface $input, OutputInterface $output) {
$installer = new \CommonGateway\BagBundle\Command\InstallCommand();
$installer->run($input, $output);
// Add post-install logic here
}
}
Dynamic Configuration
Use Symfony’s ParameterBag to load configuration dynamically:
$this->container->getParameterBag()->add([
'your_bundle.dynamic_setting'
How can I help you explore Laravel packages today?