yamcsha

#Zend - Acl

Apr 13th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2.  
  3. class App_Resources
  4. {
  5.     /* list of resources for Acl */
  6.     const PUBLIC_PAGE     = 'publicpages';
  7.     const ACCOUNT_FREE    = 'freeaccount';
  8.     const ACCOUNT_PREMIUM = 'premiumaccount';
  9.     const ADMIN_SECTION   = 'adminpages';
  10. }
  11.  
  12. class App_Roles
  13. {
  14.     // list of roles for acl
  15.     const GUEST   = 'guest';
  16.     const FREE    = 'free';
  17.     const PREMIUM = 'premium';
  18.     const ADMIN   = 'admin';
  19. }
  20.  
  21.  
  22. class App_Acl extends Zend_Acl {
  23.    
  24.     function __construct() {
  25.        
  26.         // add resources
  27.         $this->add(new Zend_Acl_Resource(App_Resources::PUBLIC_PAGE))
  28.              ->add(new Zend_Acl_Resource(App_Resources::ACCOUNT_FREE))
  29.              ->add(new Zend_Acl_Resource(App_Resources::ACCOUNT_PREMIUM))
  30.              ->add(new Zend_Acl_Resource(App_Resources::ADMIN_SECTION));
  31.        
  32.         // add roles
  33.         $this->addRole(new Zend_Acl_Role(App_Roles::GUEST))
  34.              ->addRole(new Zend_Acl_Role(App_Roles::FREE, App_Roles::GUEST))
  35.              ->addRole(new Zend_Acl_Role(App_Roles::PREMIUM, App_Roles::FREE))
  36.              ->addRole(new Zend_Acl_Role(App_Roles::ADMIN, App_Roles::PREMIUM));
  37.              
  38.         // link roles with resources
  39.         $this->allow(App_Roles::GUEST, App_Resources::PUBLIC_PAGE)
  40.              ->allow(App_Roles::FREE, App_Resources::ACCOUNT_FREE)
  41.              ->allow(App_Roles::PREMIUM, App_Resources::ACCOUNT_PREMIUM)
  42.              ->allow(App_Roles::ADMIN, App_Resources::ADMIN_SECTION);
  43.              
  44.         // premium account cannot access free account pages
  45.         $this->deny(App_Roles::PREMIUM, App_Resources::ACCOUNT_FREE);
  46.  
  47.         // restor admin access to free account pages
  48.         $this->allow(App_Roles::ADMIN, App_Resources::ACCOUNT_FREE);
  49.     }
  50. }
  51.  
  52. ?>
Add Comment
Please, Sign In to add comment