Installation:
composer require mmoreram/base-bundle
Add to config/bundles.php:
return [
// ...
Mmoreram\BaseBundle\MmoreramBaseBundle::class => ['all' => true],
];
First Use Case:
Extend SimpleBaseBundle for a new bundle:
use Mmoreram\BaseBundle\Bundle\SimpleBaseBundle;
class MyBundle extends SimpleBaseBundle
{
public function getPath(): string
{
return \dirname(__DIR__);
}
}
Key Files to Review:
src/Resources/config/services.yaml (for autowiring)src/DependencyInjection/ (for extension logic)tests/ (for functional test patterns)// src/DependencyInjection/MyExtension.php
use Mmoreram\BaseBundle\DependencyInjection\BaseExtension;
class MyExtension extends BaseExtension
{
public function load(array $configs, ContainerBuilder $container)
{
$this->processConfiguration(new MyConfiguration(), $configs);
// Custom logic here
}
}
use Mmoreram\BaseBundle\DependencyInjection\BaseConfiguration;
class MyConfiguration extends BaseConfiguration
{
public function getSupportedTypes(): array
{
return ['my_config'];
}
}
composer.json and use BaseExtension to enforce them:
public function getRequiredBundles(): array
{
return [
new \Symfony\Component\HttpKernel\KernelBundle\Bundle(),
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
];
}
BaseExtension:
public function load(array $configs, ContainerBuilder $container)
{
$container->setDefinition('my.command', new Definition(MyCommand::class));
$container->setAlias('my.command', MyCommand::class);
$container->setPublic(true, 'my.command');
}
BaseFunctionalTest:
use Mmoreram\BaseBundle\Tests\BaseFunctionalTest;
class MyBundleTest extends BaseFunctionalTest
{
protected function getKernelClass(): string
{
return MyKernel::class;
}
}
BaseKernel for isolated testing:
use Mmoreram\BaseBundle\Tests\BaseKernel;
class MyKernel extends BaseKernel
{
public function registerBundles(): array
{
return [
new MyBundle(),
];
}
}
PHP/Symfony Version Mismatch:
Circular Dependencies:
BaseExtension enforces strict bundle dependencies. Avoid circular getRequiredBundles() calls.Configuration Overrides:
BaseConfiguration requires implementing getSupportedTypes(). Omitting this may cause silent failures.Command Autowiring:
load() or they won’t appear in bin/console list.Extension Not Loading:
Verify config/bundles.php includes the bundle and that its Extension class is properly namespaced.
php bin/console debug:container mmoreram_base
Configuration Not Applied:
Check for typos in getSupportedTypes() and ensure processConfiguration() is called in load().
Functional Tests Failing:
Use BaseKernel to isolate issues. Clear cache between tests:
php bin/console cache:clear --env=test
Custom Base Classes:
Override SimpleBaseBundle or BaseExtension to enforce project-wide patterns (e.g., naming conventions).
Fast Testing Methods:
Leverage BaseFunctionalTest traits for shared test logic:
use Mmoreram\BaseBundle\Tests\Traits\FastTestMethods;
class MyTest extends BaseFunctionalTest
{
use FastTestMethods;
public function testSomethingFast()
{
$this->assertTrue($this->isFastTest());
}
}
Alias Management:
Use ExtensionAlias to simplify bundle configuration:
# config/packages/my_bundle.yaml
my_bundle:
alias: my_config
How can I help you explore Laravel packages today?