Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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');


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...