Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

php - Multiple Instances (2) of Zend_Auth

I have a CMS built on the Zend Framework. It uses Zend_Auth for "CMS User" authentication. CMS users have roles and permissions that are enforced with Zend_Acl. I am now trying to create "Site Users" for things like an online store. For simplicity sake I would like to use a separate instance of Zend_Auth for site users. Zend_Auth is written as a singleton, so I'm not sure how to accomplish this.

Reasons I don't want to accomplish this by roles:

  1. Pollution of the CMS Users with Site Users (visitors)
  2. A Site User could accidentally get elevated permissions
  3. The users are more accurately defined as different types than different roles
  4. The two user types are stored in separate databases/tables
  5. One user of each type could be signed in simultaneously
  6. Different types of information are needed for the two user types
  7. Refactoring that would need to take place on existing code
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In that case, you want to create your own 'Auth' class to extend and remove the 'singleton' design pattern that exists in Zend_Auth

This is by no means complete, but you can create an instance and pass it a 'namespace'. The rest of Zend_Auth's public methods should be fine for you.

<?php
class My_Auth extends Zend_Auth
{

    public function __construct($namespace) {
        $this->setStorage(new Zend_Auth_Storage_Session($namespace));
        // do other stuff
    }
    static function getInstance() {
        throw new Zend_Auth_Exception('I do not support getInstance');
    }  
}

Then where you want to use it, $auth = new My_Auth('CMSUser'); or $auth = new My_Auth('SiteUser');


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...