Skip to content

[Proposal] Make "App" namespace configurable #93

@predakanga

Description

@predakanga

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:

  1. Create a new project using composer create-project symfony/skeleton:3.3.x-dev foo
  2. Alter the autoload directives in composer.json to map Foo\ to src/ and Foo\Tests\ to tests/
  3. Alter src/Kernel.php, change namespace App to namespace Foo
  4. Alter web/index.php, change use App\Kernel to use Foo\Kernel
  5. Alter etc/packages/app.yaml, change App\: and App\Controller\: to Foo\: and Foo\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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions