'Twas brillig, and sinkingfish at 20/02/09 11:48 did gyre and gimble:
How do I share the acl generated in the plugin with the controller?

Assuming you will only need one instance of your ACL class, just use the singleton pattern.

You have your acl object in a singleton form (it's constructor is private and a public static getInstance() method that creates the class on first call and stores it to return on future calls).

e.g.

class My_Acl
{
  private function __construct()
  {
     // Complex stuff
  }

  public static function getInstance()
  {
    static $instance = null;
    if (is_null($instance))
      $instance = new My_Acl()
    return $instance;
  }

  // other public methods etc.
}




In order to get your ACL object in your code where you need it, you just call:
   $acl = My_Acl::getInstance();

The first time you call it the contructor will be called, on subsequent calls it will already be built.

Job Done.

You could also use Zend_Registry, but I much prefer this method when you can use it. I always feel that Zend_Registry is kinda cheating and is not too much better than global variables (not that I don't cheat myself sometimes :))

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]

Reply via email to