-
-
Notifications
You must be signed in to change notification settings - Fork 196
Description
At present, if a developer wants to use anything other than the "App" namespace for their application, they have to change their configuration in several places, and newly installed recipes often assume the default when adding their own config.
This leads to a very poor DX - for instance, consider the following process for using your own namespace:
- Create a new project using
composer create-project symfony/skeleton:3.3.x-dev foo
- Alter the autoload directives in composer.json to map
Foo\
to src/ andFoo\Tests\
to tests/ - Alter src/Kernel.php, change
namespace App
tonamespace Foo
- Alter web/index.php, change
use App\Kernel
touse Foo\Kernel
- Alter etc/packages/app.yaml, change
App\:
andApp\Controller\:
toFoo\:
andFoo\Controller\:
At this point, you have a Flex application correctly configured to use the "Foo" namespace. However, installing a single dependency can break this - for instance, simply running composer req cli
will fail.
The installation process creates a bin/console script which tries to use App\Kernel. It then tries to execute that script as part of the installation process, resulting in an error and a rollback of composer.json, leaving the recipe part installed.
Besides the poor DX (and admittedly personal preference), I would say that allowing developers to use their own namespaces facilitates code re-use and makes extracting useful functionality from an app into it's own package significantly easier.
To improve this situation, I would propose that you allow the developer to specify their own namespace in composer.json (perhaps as a key under extra), and expose this to Flex and it's recipes.
From my investigation so far, I've identified the two main locations where the namespace is hardcoded, and methods to make that configurable:
- Wrapper files like bin/console and web/index.php which do not run inside the application context need a hardcoded string - this could be achieved by adding basic variable substitution to CopyFrom*Configurator, or possibly by adding a class_alias in autoload.php
- Bundle configuration like app.yaml and doctrine.yaml have access to the application context, so these could potentially be adjusted to use a parameter (i.e. %app_namespace%) and have that automatically added to the parameters file