예제 #1
0
 /**
  * Returns a score for the selected permission
  *
  * The score is factored according to an exact match for an ARO (3), a
  * match for an inherited ARO (2) or a match for an any/all ARO (1).
  *
  * @param string $type
  * @param array $aro
  * @param string $context
  * @return integer
  */
 public function score($type, Zend_Acl_Aro $aro, $context = null)
 {
     $score = 0;
     if (!empty($this->_context[$type])) {
         $acl = $this->_context[$type];
         // determine only existing aros from type
         $defined = array_keys($acl);
         // do any parents match the existing aros?
         $parent = array_intersect($aro->getParent(), $defined);
         foreach ($parent as $id) {
             // first array member will have the highest inheritance
             $factor = $this->_getFactor($aro, $id);
             if (in_array($context, $acl[$id])) {
                 // is there an explicit match for the context?
                 $score = 4 * $factor;
             } elseif (in_array(Zend_Acl::ACO_CATCHALL, $acl[$id])) {
                 // is there an any/all for the context?
                 $score = 1 * $factor;
             }
         }
     }
     return $score;
 }