I'm not sure as to the best way to go about this...
I'm building an application that will authenticate different types of
users (ie system admins and customers) and they are maintained in
different database tables. I'd like to have each type to use a
different storage namespace.
What I've done in the past is to extend Zend_Auth and override the
getInstance() method. I've also added helper methods such as getUser()
to return a Zend_Table_Row object of the authenticated user.
<?php
class My_Auth_Client extends Zend_Auth
{
protected static $_instance = null;
public static function getInstance()
{
if (null === self::$_instance) {
self::$_instance = new self();
self::$_instance->setStorage(new
Zend_Auth_Storage_Session('Auth_Admin'));
}
return self::$_instance;
}
public function getUser()
{
$id = $this->getIdentity()->client_admin_id;
$table = new ClientAdmins();
return $table->find($id)->current();
}
}
?>
This has worked up until I tested my code on PHP v.5.2.6 and I get:
Fatal error: Call to private Zend_Auth::__construct() from context
'My_Auth_Client' in /var/www/vhosts/dev.dzcrs.com/library/My/Auth/
Client.php on line 9
Which after looking at the Zend_Auth code, makes sense (and I'm not
quite sure why it works on my 5.2.3 server).
My question is how to best accomplish this. I can extend Zend_Auth
and override getInstance to automatically set the storage by using
parent::getInstance() but then I lose any helper methods I create
since I'm returning a Zend_Auth instance rather than a My_Auth_Client
instance.
Thoughts? Am I going about this totally backwards?
Thanks,
Todd