Thursday, May 31, 2012

Re: Using PHP's Interface as Extension Point

Over engineering.

Second system effect?

The Mythical Man Month

http://en.wikipedia.org/wiki/The_Mythical_Man_Month#The_second-system_effect

On May 31, 2012, at 1:39 PM, Jamie wrote:

I suggest that you use the event system to accomplish this, as it does
exactly what you're describing:

http://book.cakephp.org/2.0/en/core-libraries/events.html

So, let's say you have a Navigation plugin and you want to gather
navigation items from every plugin in your app. When you want to
gather the items, you'd broadcast an event. You'd have listeners in
each plugin that would listen for the broadcast and return the items
you want.

- Jamie

On May 31, 9:53 am, Vinicius Dusso <vinidu...@gmail.com> wrote:
Sure, I know I'm able to use Interfaces where I want to. I just want to
know if there is a easier way to do this using the CakePHP Plugins. And if
isn't, if there is a pattern to use Interfaces and let the CakePHP
autoinclude them, like it did with the MVC classes.

Thanks,

Vinicius







On Thursday, May 31, 2012 1:07:35 PM UTC-3, jeremyharris wrote:

CakePHP is just PHP, so there's no reason you couldn't use interfaces
where you wanted to. The users of the plugins would just need to understand
that they need to implement them.

On Thursday, May 31, 2012 4:07:13 AM UTC-7, Vinicius Dusso wrote:

Hello all,

Did everyone tried to use PHP's Interface as Extension Point in CakePHP?
My idea is to create a fully modular app. To build a menu, for example, I
would be able to do something like this:

The method 'getExtensionPoint' will get all the classes that implements
the given interface, at run time.

// The core of extension point
class MenuController {

  function _buildMenu() {
    $menu = array();

    $menuProviders = $this->getExtensionPoint('IMenu');
    foreach($menuProviders as $menuProvider) {
      $menu += $menuProvider->getMenu();
    }
  }

}

// Some class ( could be a Controller or a Model ) which uses this
extension point
class User implements IMenu {

  function getMenu() {
    return array('Users' => '/user/list');
  }

}

// The Interface, to bind the extended classes
public interface IMenu {
  function getMenu();
}

Sorry for write all this code here.
Someone already did something like this? This can be done using the
plugins in CakePHP ?

Thanks in advance !

Vinicius

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: