Acl.php
00001 <?php
00011 class Dsao_Filter_Acl implements Zend_Filter_Interface
00012 {
00016 protected $_acl = null;
00017
00021 protected $_role = null;
00022
00030 public function __construct($role, Zend_Acl $acl)
00031 {
00032 $this->_role = (string) $role;
00033 $this->_acl = $acl;
00034 }
00035
00043 public function filter($array)
00044 {
00045 foreach ($array as $key => $value)
00046 {
00047
00048 if ($value instanceof Dsao_Module_Menu_Group)
00049 {
00050
00051
00052 $value->setFromArray($this->filter($value->toArray()));
00053
00054
00055 if (!$value->toArray())
00056 {
00057 unset($array[$key]);
00058 }
00059
00060 continue;
00061 }
00062
00063
00064 if (is_array($value))
00065 {
00066 $array[$key] = $this->filter($value);
00067
00068 if (empty($array[$key]))
00069 {
00070 unset($array[$key]);
00071 }
00072
00073 continue;
00074 }
00075
00076 $uri = (string) $value;
00077
00078
00079 $parts = explode('/', $uri, 4);
00080
00081
00082 if (count($parts) < 4)
00083 {
00084 throw new Dsao_Exception('dsao_filter_acl_invalid_uri');
00085 }
00086
00087
00088 $resourceCurrentModule = $parts[1];
00089
00090
00091 $resourceCurrentController = $resourceCurrentModule.'_'.$parts[2];
00092
00093
00094 $resourceCurrentAction = $resourceCurrentController.'_'.$parts[3];
00095
00096
00097 if ($this->_acl->has($resourceCurrentAction))
00098 {
00099
00100 if ($this->_acl->isAllowed($this->_role, $resourceCurrentAction))
00101 {
00102 continue;
00103 }
00104 }
00105
00106 else if ($this->_acl->has($resourceCurrentController))
00107 {
00108
00109 if ($this->_acl->isAllowed($this->_role, $resourceCurrentController))
00110 {
00111 continue;
00112 }
00113 }
00114
00115 else if ($this->_acl->has($resourceCurrentModule))
00116 {
00117
00118 if ($this->_acl->isAllowed($this->_role, $resourceCurrentModule))
00119 {
00120 continue;
00121 }
00122 }
00123
00124
00125
00126 unset($array[$key]);
00127 }
00128
00129 return $array;
00130 }
00131 }