Issues

ZF-801: Zend_Auth - Implement Singleton Pattern

Description

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:


$auth = new Zend_Auth(...);

We would have:


$auth = Zend_Auth::getInstance();

Comments

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().

Also related to storage is [ZF-804]

...and [ZF-802]

Resolved with SVN r3412.