📜 ⬆️ ⬇️

symfony loading an individual set of plugins for an application

Hello% username%.

Already repeatedly, while developing something on the symfony framework, I am faced with the question of separating the plugins of one application from another within the project. And this is necessary in order to say that plugins for the backend application are not loaded in the frontend application. What's so complicated you say, but in general, nothing. The easiest way I found is to override the setup method in the backendConfiguration class for example.

It will look like this:
Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  1. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  2. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  3. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  4. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  5. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  6. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  7. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  8. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  9. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  10. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }
  11. Copy Source | Copy HTML <?php class backendConfiguration extends sfApplicationConfiguration { public function setup() { // } public function configure() { } }

If we go this way we will get an independent configuration of plug-ins for each application, but in the end it turns out that we need to monitor the plug-ins in 3 different files. And we get three files because we have 2 applications (frontend, backend) and don't forget about cli, which only looks in the projectConfiguration. Those. if any of the plugins that you write to say, the backend will be able to work with the console, then you will definitely need to register it in the projectConfiguration, otherwise it will not work.

On the one hand, this is quite convenient, so we can make isolated applications that can be transferred from a project to a project without much getting into common configs, but if you make a complete project that does not imply such transfers (only I can be so lazy).

In general, without hesitation, I decided to make my own version of loading plugins for the symfony framework, using only the projectConfiguration and this is what happened:
Copy Source | Copy HTML
  1. <? php
  2. require_once '/usr/share/php/symfony/autoload/sfCoreAutoload.class.php' ;
  3. sfCoreAutoload :: register ();
  4. class ProjectConfiguration extends sfProjectConfiguration
  5. {
  6. public function setup ()
  7. {
  8. $ sfApplicationExists = sfConfig :: get ( 'sf_app' , false );
  9. if ( false === $ sfApplicationExists )
  10. {
  11. $ this -> enableAllPluginsExcept ( 'sfPropelPlugin' );
  12. }
  13. else
  14. {
  15. // common plugins for all applications
  16. $ sfCommonPluginsArray = array ( 'sfDoctrinePlugin' );
  17. if ( $ sfApplicationExists == 'backend' )
  18. {
  19. $ sfCustomPluginsArray = array (
  20. // plugins for backend application
  21. );
  22. }
  23. else
  24. {
  25. $ sfCustomPluginsArray = array (
  26. // plugins for frontend application
  27. );
  28. }
  29. $ this -> enablePlugins (array_merge ( $ sfCommonPluginsArray , $ sfCustomPluginsArray ));
  30. }
  31. }
  32. }

')
This method does not claim to be an ideal solution, it is extremely interesting to hear your opinion on this issue and how it can be solved differently.

PS without criticism there is no growth.

Source: https://habr.com/ru/post/89757/


All Articles