Yii Framework Forum: Component creation - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Component creation

#1 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,900
  • Joined: 04-October 08
  • Location:DC, USA

Posted 18 July 2011 - 02:50 PM

In Yii 1.x, we have Yii::createComponent() to create a new component. We also have CWidgetFactory and skin feature to systematically initialize component properties.

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.
0

#2 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 28 July 2011 - 09:26 AM

I hope this will not affect the way (ajax) events are handled - that is one thing that might be improved upon...

Nz
0

#3 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 569
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 28 July 2011 - 05:11 PM

I had some problems with the jui-widgets. I wanted to apply some basic values to all jui-widgets, so I had to create a skin file for every widget type rather than just for the base class CJuiWidget.

Would be cool if you could enable "skinning-by-parent-class".
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 28 July 2011 - 05:24 PM

Guys, it's not about JavaScript part at all, it's about configuring defaults for components like it's currently done for widgets. I like the idea but not sure about how it can be implemented without introducing another $this->widget like call.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 569
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 28 July 2011 - 06:04 PM

I don't meant in JavaScript, my posting was about PHP class attributes, e.g.
public $scriptUrl;
public $themeUrl;

Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
0

#6 User is offline   binkabir 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 194
  • Joined: 25-July 10
  • Location:Abuja,Nigeria

Posted 29 July 2011 - 06:58 AM

Hello, i think a new Dependency Container Class should be created to hold some parts of createComponents methods
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
                  )
} 
}

0

#7 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 31 July 2011 - 06:24 PM

I have argued for the unification of these two components before - I have nothing to add, except I'm happy to see that's the direction you're planning to go :-)

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!)
1

#8 User is offline   wei 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 147
  • Joined: 04-October 08

Posted 31 July 2011 - 09:32 PM

View Postmindplay, on 31 July 2011 - 06:24 PM, said:

Most days, the application component concept used in Yii does a good job...


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.
0

#9 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 569
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 01 August 2011 - 02:03 AM

Just for some inspiration, the German Wikipedia page has a list of DI-Frameworks.
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
0

#10 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 01 August 2011 - 06:52 AM

View Postwei, on 31 July 2011 - 09:32 PM, said:

This means that the cache component is coupled with the registry.


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 ;-)
0

#11 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 01 September 2011 - 07:39 PM

I've remembered an issue with config we currenty have. At least it's true for widget factory. Example: need to specify image for a grid button via widget factory but it should be relative to webroot (application can be inside of webroot directly or inside a subdir). We have to use Yii::app()->baseUrl and we can't since config is read before application is fully functional.

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.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
1

#12 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 20 September 2011 - 07:47 PM

View Postsamdark, on 01 September 2011 - 07:39 PM, said:

We have to use Yii::app()->baseUrl and we can't since config is read before application is fully functional.


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...
0

#13 User is offline   mmx 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 20-June 11
  • Location:Virginia Beach, VA USA

Posted 05 February 2012 - 01:06 AM

View Postsamdark, on 01 September 2011 - 07:39 PM, said:

I've remembered an issue with config we currenty have. At least it's true for widget factory. Example: need to specify image for a grid button via widget factory but it should be relative to webroot (application can be inside of webroot directly or inside a subdir). We have to use Yii::app()->baseUrl and we can't since config is read before application is fully functional.

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.
0

#14 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 05 February 2012 - 02:18 AM

Well, it's much more handy to get baseURL automatically. You can define constants the way you've suggested in Yii 1.1. No problem with it.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users