blacksmurf/symfony2-core-bundle
Installation
composer require blacksmurf/symfony2-core-bundle
Add the bundle to config/bundles.php:
Blacksmurf\Symfony2CoreBundle\BlacksmurfSymfony2CoreBundle::class => ['all' => true],
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 /.
Key Directories
src/Blacksmurf/Symfony2CoreBundle/: Core bundle logic.config/packages/blacksmurf_symfony2_core.yaml: Default configuration (override as needed).templates/BlacksmurfSymfony2CoreBundle/: Default Twig templates.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
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']
Twig Extensions
Register custom Twig extensions in config/packages/twig.yaml:
twig:
globals:
app_version: '%kernel.version%'
extensions:
- App\Twig\AppExtension
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
}
}
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'
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).
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.
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/).
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
Asset Pipeline Assumptions
The bundle expects a default web/ directory for assets. Customize in assets.yaml if using alternative paths (e.g., public/build/).
Enable Debug Mode
Set APP_DEBUG=1 in .env to see detailed errors and bundle logs.
Check Bundle Compilation If routes/services fail, recompile assets and dump autoload:
php bin/console assets:install public
php bin/console cache:clear
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 }
Custom Controllers
Replace the default DefaultController by:
blacksmurf_symfony2_core.homepage).config/routes.yaml.Service Decorators
Extend CoreService or other services via decorators (see Implementation Patterns).
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!";
}
}
Database Migrations The bundle lacks built-in migrations. Use Doctrine Migrations or custom commands:
php bin/console make:migration
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
How can I help you explore Laravel packages today?