I’ve written some code to improve filtering in grid views and I’m considering packaging it up as an extension for other people to use.
The extension is split into several classes, each of which have some configurable properties. How should I set up the application component so that the user can configure the individual components from their main config file?
I’ve considered adding a property to the application component class that looks something like this:
public $filterConfig = array( 'ComponentClassName'=>array( 'property1'=>'defaultValue', ... ), ... );
and then calling Yii::createComponent() to construct each instance of each component. The down side is that the default values are no longer stored in the component classes themselves, which seems like poor encapsulation. It might also impact extensibility.
Is there a recommended way to handle this? Any suggestions would be appreciated.
It occurs to me that I can keep the default config in the separate components and keep the application component’s configuration as simple as:
$filterConfig = array( 'FilterClass1'=>array( 'class'=>'path.to.FilterClass1', ), 'FilterClass2'=>array( 'class'=>'path.to.FilterClass2', ), ... );
The user could still override the default config. This would also mean that the user could add their own filter classes via config.
Is this the right thing to do?