Component creation
#1
Posted 18 July 2011 - 02:50 PM
In Yii 2.0, we hope we can unify both of them, and if possible we can make use of the dependency injection pattern. Of course, we still want the creation process to be efficient, since it is directly related with the overall performance of the framework.
If you have any idea, please discuss it here. Thanks.
#2
Posted 28 July 2011 - 09:26 AM
Nz
#3
Posted 28 July 2011 - 05:11 PM
Would be cool if you could enable "skinning-by-parent-class".
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#4
Posted 28 July 2011 - 05:24 PM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#5
Posted 28 July 2011 - 06:04 PM
public $scriptUrl; public $themeUrl;
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#6
Posted 29 July 2011 - 06:58 AM
and the CwidgetFactory methods and properties all together, this new class CDependencyContainer should
handle some default values for some properties of the components.
//can be abstract or interface abstract class CDependencyContainer{ public $params_cwidgetFactory=array(); public $params_components=array(); public function __construct($params=null,$something=false){ $this->params_components = $params; //by default the $params_components should load some if(empty($this->params_components )) // load all default values for component creation else( //load the user defined params ) } }
#7
Posted 31 July 2011 - 06:24 PM
As for dependency injection - I have yet to see a truly good implementation in PHP, and frankly I have my doubts as to the usefulness of this pattern in the PHP language.
Most days, the application component concept used in Yii does a good job - and I realize this is not dependency injection, but it is a component registry, such as is commonly used (in some form or another) in DI implementations.
The component registry tends to work well in PHP, and many frameworks implement one. I'm not convinced that the additional benefits of DI are worth the complexity and overhead they add. And I'm not saying there aren't benefits, but given that DI is not a simple pattern to understand in the first place, I think you will find that very few people will be able to use it correctly (or willing to use it at all) to begin with. It just doesn't lend itself well to the average PHP developers pragmatic approach to programming.
That, and as said, show me an implementation in PHP that performs well, actually does DI, and is easy to understand and implement? (I would love to see one, but yours would be the first!)
#8
Posted 31 July 2011 - 09:32 PM
mindplay, on 31 July 2011 - 06:24 PM, said:
I agree with this sentiment, the application component as a registry is a good compromise for most uses. It is also a simpler concept to understand and use. There is a tricky point with regards to components that require another component, e.g. a db cache component needing a db component. Currently, the cache component would accept a db id string and during init, it will reference this db from the registry. This means that the cache component is coupled with the registry.
#9
Posted 01 August 2011 - 02:03 AM
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#10
Posted 01 August 2011 - 06:52 AM
wei, on 31 July 2011 - 09:32 PM, said:
I'm not really concerned with that, given that the entire application is probably coupled with the registry to begin with.
Of course, with DI, you could decouple it all, which would make your unit tests more consistent - even if currently it's not a great hassle to just replace certain application components during test runs.
As said, I'm not against DI - unless it's as bad as the other PHP implementations I've seen ;-)
#11
Posted 01 September 2011 - 07:39 PM
Possible solution:
Allow using anonymous functions in config. If config item is anonymous function, execute it and use result during component initialization. This was I'll be able to postpone calling Yii::app()->baseUrl and it will work.
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#12
Posted 20 September 2011 - 07:47 PM
samdark, on 01 September 2011 - 07:39 PM, said:
I have run into this problem myself - it seems more to be a problem with the way configuration is created.
In my own applications, I've been using a custom configuration framework, which allows multiple layers of configuration - e.g. a fixed base configuration, separate layers on top of that for live/test/dev sites, and another layer on top of that with your local overrides.
More to the point, this configuration-class runs prior to loading/initializing the framework and application object, and allows each layer to use the configuration values provided by the previous layer. Things like base URL or other base paths/URLs are configured in the fixed base configuration, so that live/test/dev/local configurations can aggregate these values.
I could find sample code and post it if there's any interest...
#13
Posted 05 February 2012 - 01:06 AM
samdark, on 01 September 2011 - 07:39 PM, said:
Possible solution:
Allow using anonymous functions in config. If config item is anonymous function, execute it and use result during component initialization. This was I'll be able to postpone calling Yii::app()->baseUrl and it will work.
Does baseUrl have to be a method? Would it make sense for Yii to load a constants.php from the config/ directory and define the base URL there. Then you can create a helper file to use the base url anywhere you needed it or use the constant directly in cases where you cannot use a helper.
#14
Posted 05 February 2012 - 02:18 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark