Weave 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

Symfony2 Core Bundle Laravel Package

blacksmurf/symfony2-core-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require blacksmurf/symfony2-core-bundle
    

    Add the bundle to config/bundles.php:

    Blacksmurf\Symfony2CoreBundle\BlacksmurfSymfony2CoreBundle::class => ['all' => true],
    
  2. First Use Case: Basic Configuration The bundle provides a default Symfony2 structure (controllers, services, and basic routing). Verify the default routes by running:

    php bin/console debug:router
    

    Access the default welcome page at /.

  3. Key Directories

    • src/Blacksmurf/Symfony2CoreBundle/: Core bundle logic.
    • config/packages/blacksmurf_symfony2_core.yaml: Default configuration (override as needed).
    • templates/BlacksmurfSymfony2CoreBundle/: Default Twig templates.

Implementation Patterns

Workflows

  1. Extending Default Controllers Override the default DefaultController in your own bundle or application:

    // src/Controller/DefaultController.php
    namespace App\Controller;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    
    class DefaultController extends AbstractController {
        public function index() {
            return $this->render('default/index.html.twig');
        }
    }
    

    Update routing in config/routes.yaml:

    app_homepage:
        path: /
        controller: App\Controller\DefaultController::index
    
  2. Service Integration The bundle includes a CoreService for common logic (e.g., logging, utilities). Extend it:

    # config/services.yaml
    services:
        App\Service\CoreServiceExtension:
            decorates: blacksmurf_symfony2_core.core_service
            arguments: ['@.inner']
    
  3. Twig Extensions Register custom Twig extensions in config/packages/twig.yaml:

    twig:
        globals:
            app_version: '%kernel.version%'
        extensions:
            - App\Twig\AppExtension
    
  4. Event Listeners Subscribe to bundle events (e.g., core.initialize):

    // src/EventListener/CoreListener.php
    namespace App\EventListener;
    use Blacksmurf\Symfony2CoreBundle\Event\CoreEvents;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class CoreListener implements EventSubscriberInterface {
        public static function getSubscribedEvents() {
            return [CoreEvents::INITIALIZE => 'onCoreInitialize'];
        }
        public function onCoreInitialize() {
            // Custom logic
        }
    }
    
  5. Asset Management Use the bundle’s default asset pipeline or override in config/packages/assets.yaml:

    assets:
        version: '1.0.*'
        packages:
            app:
                manifest: '%kernel.project_dir%/public/build/manifest.json'
    

Gotchas and Tips

Pitfalls

  1. Namespace Conflicts The bundle uses Blacksmurf\Symfony2CoreBundle namespace. Avoid naming your classes/services similarly to prevent autoloading issues. Fix: Use unique prefixes (e.g., App\Service\ExtendedCoreService).

  2. Configuration Overrides The bundle’s blacksmurf_symfony2_core.yaml may not be auto-loaded if misplaced. Ensure it’s in config/packages/ or explicitly imported in config/bundles.php.

  3. Deprecated Symfony2 Features The bundle assumes Symfony 2.x conventions (e.g., AppKernel). If upgrading to Symfony Flex or 3+/4+/5+, adapt configurations (e.g., config/packages/ instead of app/config/).

  4. Event Dispatcher Quirks Events like core.initialize are not documented. Inspect the bundle’s EventDispatcher class for available events:

    // src/Blacksmurf/Symfony2CoreBundle/Event/CoreEvents.php
    
  5. Asset Pipeline Assumptions The bundle expects a default web/ directory for assets. Customize in assets.yaml if using alternative paths (e.g., public/build/).


Debugging Tips

  1. Enable Debug Mode Set APP_DEBUG=1 in .env to see detailed errors and bundle logs.

  2. Check Bundle Compilation If routes/services fail, recompile assets and dump autoload:

    php bin/console assets:install public
    php bin/console cache:clear
    
  3. Log Bundle Events Add a temporary listener to debug events:

    // src/EventListener/DebugListener.php
    use Psr\Log\LoggerInterface;
    class DebugListener {
        public function __invoke($event) {
            \Log::debug('Event:', ['name' => $event->getName()]);
        }
    }
    

    Subscribe in services.yaml:

    services:
        App\EventListener\DebugListener:
            tags:
                - { name: kernel.event_listener, event: core.initialize, method: __invoke }
    

Extension Points

  1. Custom Controllers Replace the default DefaultController by:

    • Removing the bundle’s route (blacksmurf_symfony2_core.homepage).
    • Adding your own route in config/routes.yaml.
  2. Service Decorators Extend CoreService or other services via decorators (see Implementation Patterns).

  3. Twig Filters/Functions Add custom Twig logic by creating an extension:

    // src/Twig/AppExtension.php
    namespace App\Twig;
    use Twig\Extension\AbstractExtension;
    use Twig\TwigFunction;
    
    class AppExtension extends AbstractExtension {
        public function getFunctions() {
            return [new TwigFunction('app_greet', [$this, 'greet'])];
        }
        public function greet($name) {
            return "Hello, $name!";
        }
    }
    
  4. Database Migrations The bundle lacks built-in migrations. Use Doctrine Migrations or custom commands:

    php bin/console make:migration
    
  5. Security Integration Integrate with Symfony’s security component by extending the bundle’s security.yaml:

    security:
        firewalls:
            main:
                pattern: ^/
                anonymous: ~
                form_login:
                    login_path: blacksmurf_symfony2_core_login
                    check_path: blacksmurf_symfony2_core_login_check
    
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.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle