Symfony Flex as the new workflow to create Symfony application is awesome. It is quite easy to add or remove bundles by
composer req cli
# or
composer req symfony/console
Reciepes are responsible to create a pre configuration for bundles to register, configuration to set, env variables ... You can create your own reciepes by commiting to one of the repositories (contributors or main)
As a maintainer of the Symfony CMF i currently try to build our reciepes and a i faced a problem, that has been there before, but gets visible on our and depending bundles now:
As the bundles i require (and their dependencies) are registered directly, errors in configuration will
be visible on demand as the process of requiring is closed by a make cache-warmup
in most cases.
Which errors can occur?
- general missing dependencies
- enabling of optional features, which require extra dependencies
- configurations, which are required but are not served by a reciepe as defaults
Those issues can occur on the required bundle itself or on a dependency in the required bundle.
I could adjust the configuration and registered bundles manually, but i lost the required bundle in my composer
process, as composer resets its changes on error. and i am unsure if flex would overwrite manual changes on
a second composer req a/b
call.
Caused by those issues and lots of tries to fix them or tries to think about them i created several issues on several symfony repositories. Those issues are no critics on flex. I just try to understand it and wanna make it stable.
But what about those issues in the bundles i require?
Is it fair to say: I demand clean bundles.
- a
composer require bundle
will go through without any manual configuration on an empty symfony application (including registering bundle) - default configuration of a bundle does not require more dependencies, then defined in require section of the composer.json
- if a configuration is required a reciepe exists with default values
- dependencies for optional features are not required directly, but a clear advice existes how to get them (required bundles, configuration
I mean, that sounds valid and should be tested in all cases, but i personaly have a problem with a bundle i created.
The issues are more visible now as the bundles are registered directly via flex. But we would see same behavior
on older symfony apps, when we would register bundles directly. But here the user is led through the installation
process by a documentation. And that hides several issues. As a bundle developer i must admit, that the issues are
also hidden for us. Our tests got the support of require-dev
in composer.json. So all dependencies are available
and the configuration is set to the values we whant it. Mostly we have got a sandbox with all the dependencies we need.
There it works fine.
But the user is the one, who gets the error when installing our bundles (for the first time). So we should test our
bundles to get the same experiences a new user would have. I created
a little script to bootstrap a tiny symfony app and
require each of our bundles on it. Doing so i can fetch the errors on an make cache-warmup
. If somebody
likes the script i would add it i would add it to our testing component.
So what about developing clean bundles and have more fun working with Symfony Flex?
Can damand from a symfony bundle to be installable without manual intervention with default/empy configuration? If yes, how should we bundle devs proof it?
You could add to this notes that a bundle must not be dependent on the bundles loading order. See sonata-project/SonataCacheBundle#166.