Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Base Bundle Laravel Package

mmoreram/base-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require mmoreram/base-bundle
    

    Add to config/bundles.php:

    return [
        // ...
        Mmoreram\BaseBundle\MmoreramBaseBundle::class => ['all' => true],
    ];
    
  2. 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__);
        }
    }
    
  3. Key Files to Review:

    • src/Resources/config/services.yaml (for autowiring)
    • src/DependencyInjection/ (for extension logic)
    • tests/ (for functional test patterns)

Implementation Patterns

Core Workflows

1. Bundle Structure

  • BaseBundle Extension:
    // 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
        }
    }
    
  • Configuration Class:
    use Mmoreram\BaseBundle\DependencyInjection\BaseConfiguration;
    
    class MyConfiguration extends BaseConfiguration
    {
        public function getSupportedTypes(): array
        {
            return ['my_config'];
        }
    }
    

2. Dependency Management

  • Declare dependencies in composer.json and use BaseExtension to enforce them:
    public function getRequiredBundles(): array
    {
        return [
            new \Symfony\Component\HttpKernel\KernelBundle\Bundle(),
            new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        ];
    }
    

3. Command Integration

  • Register commands via 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');
    }
    

4. Functional Testing

  • Extend BaseFunctionalTest:
    use Mmoreram\BaseBundle\Tests\BaseFunctionalTest;
    
    class MyBundleTest extends BaseFunctionalTest
    {
        protected function getKernelClass(): string
        {
            return MyKernel::class;
        }
    }
    
  • Use BaseKernel for isolated testing:
    use Mmoreram\BaseBundle\Tests\BaseKernel;
    
    class MyKernel extends BaseKernel
    {
        public function registerBundles(): array
        {
            return [
                new MyBundle(),
            ];
        }
    }
    

Gotchas and Tips

Common Pitfalls

  1. PHP/Symfony Version Mismatch:

    • The bundle requires PHP 7.2+ and Symfony 4.3+. Downgrading may break autowiring or dependency injection.
  2. Circular Dependencies:

    • BaseExtension enforces strict bundle dependencies. Avoid circular getRequiredBundles() calls.
  3. Configuration Overrides:

    • Extending BaseConfiguration requires implementing getSupportedTypes(). Omitting this may cause silent failures.
  4. Command Autowiring:

    • Commands must be explicitly registered in load() or they won’t appear in bin/console list.

Debugging Tips

  • 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
    

Extension Points

  1. Custom Base Classes: Override SimpleBaseBundle or BaseExtension to enforce project-wide patterns (e.g., naming conventions).

  2. 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());
        }
    }
    
  3. Alias Management: Use ExtensionAlias to simplify bundle configuration:

    # config/packages/my_bundle.yaml
    my_bundle:
        alias: my_config
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui