sulu / skeleton

Project template for starting your new project based on the Sulu content management system
https://sulu.io
MIT License
261 stars 81 forks source link

Support changing the kernel context of the console per ENV #214

Closed stollr closed 1 year ago

stollr commented 1 year ago
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets -
Related issues/PRs -
License MIT
Documentation PR -

What's in this PR?

This PR makes it possible to define the kernel context for the console commands per ENV variables.

Why?

Symfony provides several debugging commands. For example you can debug the container to list all services with a specified tag. For example

bin/console debug:container --tag controller.service_arguments

 -------------------------------------------------------------- -------------------------------------------------------------- 
  Service ID                                                     Class name                                                    
 -------------------------------------------------------------- -------------------------------------------------------------- 
  kernel                                                         App\Kernel                                                    
  App\Controller\Admin\AssociationController                     App\Controller\Admin\AssociationController                    
  Doctrine\Bundle\DoctrineBundle\Controller\ProfilerController   Doctrine\Bundle\DoctrineBundle\Controller\ProfilerController  
 -------------------------------------------------------------- -------------------------------------------------------------- 

The problem is that this command would only list the admin controllers. All controllers of the website context will be hidden.

Example Usage

To change the kernel context, it will be possible to easily get the services of the website context. This could be done by prefixing the console command with SULU_CONTEXT=website

SULU_CONTEXT=website bin/console debug:container --tag controller.service_arguments

 -------------------------------------------------------------- -------------------------------------------------------------- 
  Service ID                                                     Class name                                                    
 -------------------------------------------------------------- -------------------------------------------------------------- 
  kernel                                                         App\Kernel                                                    
  App\Controller\Website\RegistrationController                  App\Controller\Website\RegistrationController                 
  Doctrine\Bundle\DoctrineBundle\Controller\ProfilerController   Doctrine\Bundle\DoctrineBundle\Controller\ProfilerController  
  sulu_website.default_controller                                Sulu\Bundle\WebsiteBundle\Controller\DefaultController        
 -------------------------------------------------------------- --------------------------------------------------------------

Alternatively you can export the variable to the environment of subsequently executed commands. This will give you the same result as in the above example.

export SULU_CONTEXT=website
bin/console debug:container --tag controller.service_arguments
alexander-schranz commented 1 year ago

I don't think this make sense to have 2 ways todo the same thing. There exist specific for this case the bin/websiteconsole:

bin/websiteconsole debug:container --tag controller.service_arguments

Having two ways of doings things is mostly bad. Still it is possible as you mostly already know to adopt this in your project if it is a requirement for you.

alexander-schranz commented 1 year ago

Also keep in mind you should not build something baseed on the sulu.context. As the Two Kernel Setup will be one of the things which will be removed in the future.

stollr commented 1 year ago

Okay, now I understand the difference between bin/adminconsole and bin/websiteconsole. That wasn't completely clear to me, until now.

Also keep in mind you should not build something baseed on the sulu.context. As the Two Kernel Setup will be one of the things which will be removed in the future.

Understood.