Symfony Bundle Skeleton
derafu/symfony-bundle-skeleton is the base for reusable Derafu bundles targeting PHP 8.5 and Symfony 8.1. Its Composer type is symfony-bundle.
Create a new bundle with:
composer create-project derafu/symfony-bundle-skeleton my-bundle --stability=dev
Structure
src/
ProjectBundle.php
Contract/GreetingServiceInterface.php
Service/GreetingService.php
resources/config/
symfony-project-bundle-services.yaml
tests/
fixtures/Kernel.php
fixtures/GreetingConsumer.php
fixtures/services.yaml
src/ProjectBundleTest.php
ProjectBundle extends Symfony’s AbstractBundle. Its configure() hook defines the configuration tree, and loadExtension() imports the YAML and exposes the validated options as container parameters. The bundle root is the package directory, including when the bundle class lives in src/.
The example configuration is:
# config/packages/derafu_project.yaml
derafu_project:
message: 'Hello from the application.'
The default message is Hello from the project bundle. Empty messages, non-string values and unknown options are rejected by Symfony’s configuration system.
The private service ID is
Derafu\ProjectBundle\Contract\GreetingServiceInterface, implemented by
Derafu\ProjectBundle\Service\GreetingService. Consumers inject the
interface; no named service or concrete-class alias is required. Its greet()
method returns the configured message unchanged.
The Symfony configuration block remains derafu_project. Its validated
message option becomes the container parameter derafu.project.message:
the public configuration alias and internal parameter name serve different
purposes.
services:
Derafu\ProjectBundle\Contract\GreetingServiceInterface:
class: Derafu\ProjectBundle\Service\GreetingService
arguments:
$message: '%derafu.project.message%'
The production YAML includes concise conventions: interface service IDs, private
services, package-qualified parameters, tagged collections and shared dependency
services. Interfaces document their contracts, and implementing methods inherit
that documentation with {@inheritDoc}.
Register the bundle in the consuming application’s config/bundles.php:
return [
Derafu\ProjectBundle\ProjectBundle::class => ['all' => true],
];
Adapt the Template
Rename the Composer package and metadata, Derafu\ProjectBundle and Derafu\TestsProjectBundle namespaces, the bundle class, the derafu_project configuration alias, parameter and service prefixes, and the YAML filename together. Update the import in loadExtension() and the test kernel’s bundle registration and configuration accordingly.
For an actual bundle named derafu/symfony-example-bundle, use a filename such as resources/config/symfony-example-bundle-services.yaml. Keep the same base structure, configuration hooks, explicit wiring and verification conventions across bundles.
Replace the greeting example with the bundle’s actual integration. Add compiler passes, assets, translations or other resources when the feature requires them. Form, Twig and Derafu Translation are not dependencies of this template.
Verification
ProjectBundleTest boots a real application with FrameworkBundle and the
project bundle, loading the production service YAML through loadExtension().
It verifies registration, root path, configuration alias, default and custom
messages, and rejection of invalid options.
The application fixture YAML registers GreetingConsumer with autowiring.
Its constructor receives GreetingServiceInterface, proving that an application
can use the private bundle service through its contract without reconstructing
the bundle’s service graph. These functional checks share one integration suite;
no separate structural service/alias test is needed.
The fixture keeps generated cache and logs in an isolated temporary project and restores environment changes made by Symfony’s debug kernel. Symfony’s native kernel is intentional here: this template tests a Symfony bundle inside a real FrameworkBundle application.
Run from the package root:
composer update
composer validate --strict
composer tests
composer phpstan
composer phpcs
PHPStan runs at level 9 over src/ and tests/. PHPUnit requires coverage metadata and fails on warnings, notices, deprecations and risky tests. Coverage and test reports are written under var/. The CI workflow runs the same checks on PHP 8.5.