how to extend various core classes that are instantiated via the 'new' operator and a string literal

Basically, Yii has a bunch of objects instantiated like this for example:




new CEvent; 



So check it. That means the bulk of the classes that make up the framework cannot be easily extended like these ones:

http://www.yiiframework.com/doc/guide/1.1/en/basics.application#core-application-components

aka, “CApplicationComponent” classes. It’s a pattern i use all the time for my own classes I want globally accessible from Yii::app(). It’s great for switching in your own extended versions of those classes in the main.php config file, etc. BUT, there are very many classes that can’t be extended that way. And often you have to go around and change 2-4 classes as a result that can be extended just so that everywhere ‘new CEvent’ is created, it’s creating ‘new CustomEvent’.

So wouldn’t it be possible to instantiate all objects via Yii::createComponent() rather than use the ‘new’ operator, and then in createComponent() add some code to dynamically search for replacement classes you specified in the main.php config file? It seems like a replace-all sort of job where you could replace all the objects instantiated with ‘new’ automatically to be instantiated with createComponent(). Or even it had to be done by hand, it doesn’t seem like it would take much time.

Am I alone here as the only one that’s extended 2+ additional classes so they instantiate objects from a new extended class???

Thoughts?

I’ve not personally had any need to extend any of the core classes. Could you give an example of how and why you’re extending them?

For example the way CClientScript put the css files inside <head>, is not very convenient

Extending CClientScript just for overriding renderHead()