symfony download an individual set of plugins for the application

    Hello,% username%.

    Already repeatedly, developing something on the symfony framework, I come across the issue of separating the plugins of one application from another within the project. But this is necessary in order to say plugins for the backend application are not loaded in the frontend application. What is difficult you say, but in general nothing. The easiest way I've found is to override the setup method in the backendConfiguration class for an example.

    It will look like this:
    Copy Source | Copy HTML
    1.  
    2. class backendConfiguration extends sfApplicationConfiguration
    3. {
    4.   public function setup()
    5.   {
    6.     // подключаем нужные нам плагины
    7.   }
    8.   public function configure()
    9.   {
    10.   }
    11. }
    12.  

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

    On the one hand, it’s quite convenient, so we can make isolated applications that can be transferred from project to project without much need to fit into common configs, but if you do a whole project that doesn’t mean such transfers (maybe I’m the only one so lazy).

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


    This method does not claim to be the perfect solution, it is extremely interesting to listen to your opinion on this issue and how it can be solved in another way.

    PS there is no growth without criticism.

    Also popular now: