Thursday, May 31, 2012

Re: Using PHP's Interface as Extension Point

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: