Description
Description
Right now, loading actions or controllers on debug
mode only is very messy. A lot of solutions exists, but none of them are, in my point of view, "clean".
Example
Let's say you want to create a Controller with actions that will allow your team to access your app emails in the browser.
You can easily do this with 2 proposition.
Proposition A
Already fixed/implemented in #30379 as pointed by @ro0NL
Allow expression language to use app variable inside the condition key
Right now only context
and request
can be used.
<?php
namespace App\Controller;
class DebugEmailController extends AbstractController
{
/**
* @Route("/debug/email/registration", condition="%kernel.debug%")
*/
public function registrationEmail()
{
}
}
Proposition B
Like resource loading for service, offer a way to exclude/ignore a pattern of Controllers
like:
// config/routes/annotations.yaml
controllers:
resource: ../../src/Controller/
type: annotation
exclude: '../src/Controller/{DebugEmailController}.php'
// config/routes/dev/annotations.yaml
controllers:
resource: ../../src/Controller/DebugEmailController.php
type: annotation
Existing and not fine solutions for this case are:
Write the routes of this controller in `yml` and import them only in `dev/routing.yaml`
You are forcing the developper to switch formats which is bad. If they choose annotations for their entire application/company, then you would have 1% of route defined as yaml
as an exception just because you can't do it with sticking with annotation
format.
You would never recommend to write service registration in .yaml
and then, because you want to do something different, adivse them to write them in .xml
format.
Write code inside each action of your controller to return a 404 if `app.debug === true`
The cons of this: That would work, but Symfony would still load this routes (also, code duplication).
Put the `DebugEmailController` outside `src/Controller/`
Same remark than before, you would have 99% of your Controller
under the "standardized" folder, but then 1% inside a different place to allow to load it only in debug mode ?
Create a bundle and require it only in dev-deps with composer
Well that works well but in this use case, some of the code relies in your application, so it would mean that the bundle will search for templates that lives under /templates
. It also create unecessary complexity to work with.
Is there any technical/functional reasons not to have already one of those 2 solution implemented that i'm not aware of ?