Pink-Crab / Perique-Framework

The Perqiue Plugin Framework for WordPress
5 stars 0 forks source link

[V2] Improve Module Bootstrapping #78

Closed gin0115 closed 1 year ago

gin0115 commented 1 year ago

The was modules are currently added to perique is a bit messy.

Currelty many have both a Static method which is used to add all hooks and then if there is middleware, this needs adding also.

Would like to have the means to have a function on the App_Factory will allows you to just add the module name and it handles it all internally.

$app_factory
   ->add_module(Module::class)
   ->add_module(Another_Module::class, function(Another_Module $module): Another_Module{
      $module->some_setup('value);
      return $module;
   })
gin0115 commented 1 year ago

this has been implemented slightly differently.


$app_factory
   ->module(Module::class)
   ->module(
       Another_Module::class, 
       function(Another_Module $module, ?Registation_Middleware $middleware): Another_Module{
          $module->some_setup('value);
          $middleware->set_config('vale');
          return $module;
       }
    );
``
gin0115 commented 1 year ago

this can also be done both before and after the Module_Manager is defined in the App instance.

If called before, it stacks them in array, these are then added when the Module_Manager is defiend