pradosoft / prado

Prado - Component Framework for PHP
Other
187 stars 70 forks source link

RFI: TModule::init loads [configuration] behaviors. #971

Open belisoful opened 1 year ago

belisoful commented 1 year ago

After studying other platforms a bit, It would be nice to be able to define behaviors within the configuration of a module rather than from an instance of TBehaviorsModule.

Proposal: TModule::init($config) is expanded to read $config for <behavior class='xyz' /> and $config['behaviors'] => behavior|array[behavior]. a behavior is a TBaseBehavior subclass or a string class name or an array for Prado::createComponent.

This will add behaviors to modules. This does replicate the function of TBehaviorModule, but in a way similar to Yii. Also, if modules are getting behavior support, then the main application (and the application configuration) should also get behaviors that apply to the application.

behaviors could also be a page level selection configuration.

belisoful commented 1 year ago

Maybe there could be a protected TModule::getModuleBehaviorObject() {return $this;}. This way a module (ahem: TDataSourceConfig) a module can route a module's configuration behaviors to a managed object, like TDbConnection.

module configuration of behaviors should be in a function by itself. If managed objects are lazy loaded, the behaviors can be "not applied", but stored, and attached when the lazy loading object is loaded.

ctrlaltca commented 1 year ago

Sounds like a nice improvement