What is the difference between Phalcon\Mvc\User\Plugin and Phalcon\Mvc\User\Component?
|
Apr '15 |
7 |
7659 |
6 |
A plugin is like the Security plugin in INVO (https://github.com/phalcon/invo/blob/master/app/plugins/Security.php#L13), it implements methods as events of some component, in this case Dispatcher (https://github.com/phalcon/invo/blob/master/public/index.php#L43)
A component is a class or group of classes that provide custom functionality to the application but aren't aware of events, like the Elements class: https://github.com/phalcon/invo/blob/master/app/library/Elements.php
Yep, a plugin is like a listener, however both classes don't have any real differences, they extend from Phalcon\DI\Injectable to easily access the service locator
Controllers handles the application login in the MVC but again can be used as a plugin if registered in the services using the di component.
Just as it sounds. The way I understand plugins and components is that, component can be used independently but plugins (as they sound) have to be plugged in a component or module so to speak in order to execute. That's why plugins rely heavily to events (action from the user) on run time. Plugins can extend the functionability of a component by adding some behaviours. A good example can be; A car (component) can be driven when it is raining(event) without wipers(plugins). But with wipers the car can be driven much better due to behavior change in weather.
From this anology plugin can make a component fit in different usability while reducing the number of bugs.