ZF-801: Zend_Auth - Implement Singleton Pattern

Issue Type: Improvement Created: 2007-01-26T08:06:02.000+0000 Last Updated: 2007-07-05T14:43:42.000+0000 Status: Resolved Fix version(s): - 0.8.0 (21/Feb/07)

Reporter: Darby Felton (darby) Assignee: Darby Felton (darby) Tags: - Zend_Auth

Related issues: Attachments:


If we restrict Zend_Auth to providing for authenticating HTTP requests to the application, then we need only one instance of the authentication object per PHP execution space. It is best for the component design that Zend_Auth focus on supporting the generalized use case of authenticating the HTTP request against the web application. All things considered, Zend_Auth is a good candidate for implementing the Singleton pattern, since only one instance is needed per request. Of course, the one instance could bind to any of various authentication adapters included with Zend_Auth or to a custom adapter written by the user.

By implementing the Singleton pattern, there is a side benefit of inherently providing global access to the object instance.

Instead of:

<pre class="highlight">
$auth = new Zend_Auth(...);

We would have:

<pre class="highlight">
$auth = Zend_Auth::getInstance();


Posted by Ralph Schindler (ralph) on 2007-02-02T13:42:59.000+0000

Also keep in mind that in addition to binding to different Auth Adapters, it can be bound to different Storage Mechanisms.. With that in mind, if component A and component B really want to maintain different authentication identities (extreme edge case), they can both do so within the same session, simply by using a different namespace in the ZendSession storage type adapter.

getInstance (like Zend_Contoller) should be complemented with a resetInstance().

Posted by Darby Felton (darby) on 2007-02-02T14:36:19.000+0000

Also related to storage is [ZF-804]

Posted by Darby Felton (darby) on 2007-02-02T14:37:13.000+0000

...and [ZF-802]

Posted by Darby Felton (darby) on 2007-02-14T16:32:55.000+0000

Resolved with SVN r3412.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.