/**
  * Returns an array of MatchingRule objects for the specified server.
  * The key of each entry is the OID of the matching rule.
  */
 function MatchingRules($dn = null)
 {
     # Set default return
     $return = null;
     if ($return = get_cached_item($this->server_id, 'schema', 'matchingrules')) {
         debug_log('%s::MatchingRules(): Returning CACHED [%s] (%s).', 25, get_class($this), $this->server_id, 'matchingrules');
         return $return;
     }
     # build the array of MatchingRule objects
     $raw_matching_rules = $this->getRawSchema('matchingRules', $dn);
     if ($raw_matching_rules) {
         $rules = array();
         foreach ($raw_matching_rules as $rule_string) {
             if (is_null($rule_string) || 0 == strlen($rule_string)) {
                 continue;
             }
             $rule = new MatchingRule($rule_string);
             $key = strtolower($rule->getName());
             $rules[$key] = $rule;
         }
         ksort($rules);
         /* For each MatchingRuleUse entry, add the attributes who use it to the
            MatchingRule in the $rules array.*/
         $raw_matching_rule_use = $this->getRawSchema('matchingRuleUse');
         if ($raw_matching_rule_use != false) {
             foreach ($raw_matching_rule_use as $rule_use_string) {
                 if ($rule_use_string == null || 0 == strlen($rule_use_string)) {
                     continue;
                 }
                 $rule_use = new MatchingRuleUse($rule_use_string);
                 $key = strtolower($rule_use->getName());
                 if (isset($rules[$key])) {
                     $rules[$key]->setUsedByAttrs($rule_use->getUsedByAttrs());
                 }
             }
         } else {
             /* No MatchingRuleUse entry in the subschema, so brute-forcing
                the reverse-map for the "$rule->getUsedByAttrs()" data.*/
             $attrs = $this->SchemaAttributes($dn);
             if (is_array($attrs)) {
                 foreach ($attrs as $attr) {
                     $rule_key = strtolower($attr->getEquality());
                     if (isset($rules[$rule_key])) {
                         $rules[$rule_key]->addUsedByAttr($attr->getName());
                     }
                 }
             }
         }
         $return = $rules;
         # cache the schema to prevent multiple schema fetches from LDAP server
         set_cached_item($this->server_id, 'schema', 'matchingrules', $return);
     }
     debug_log('%s::MatchingRules(): Entered with (%s), Returning (%s).', 25, get_class($this), $dn, $return);
     return $return;
 }
Esempio n. 2
0
 /**
  * Returns an array of MatchingRule objects for the specified server.
  * The key of each entry is the OID of the matching rule.
  */
 public function MatchingRules($method = null, $dn = '')
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     # Set default return
     $return = null;
     if ($return = get_cached_item($this->index, 'schema', 'matchingrules')) {
         if (DEBUG_ENABLED) {
             debug_log('Returning CACHED [%s] (%s).', 25, 0, __FILE__, __LINE__, __METHOD__, $this->index, 'matchingrules');
         }
         return $return;
     }
     # build the array of MatchingRule objects
     $raw = $this->getRawSchema($method, 'matchingRules', $dn);
     if ($raw) {
         $rules = array();
         foreach ($raw as $line) {
             if (is_null($line) || !strlen($line)) {
                 continue;
             }
             $rule = new MatchingRule($line);
             $key = $rule->getName();
             $rules[$key] = $rule;
         }
         ksort($rules);
         /* For each MatchingRuleUse entry, add the attributes who use it to the
          * MatchingRule in the $rules array.*/
         $raw = $this->getRawSchema($method, 'matchingRuleUse');
         if ($raw != false) {
             foreach ($raw as $line) {
                 if (is_null($line) || !strlen($line)) {
                     continue;
                 }
                 $rule_use = new MatchingRuleUse($line);
                 $key = $rule_use->getName();
                 if (isset($rules[$key])) {
                     $rules[$key]->setUsedByAttrs($rule_use->getUsedByAttrs());
                 }
             }
         } else {
             /* No MatchingRuleUse entry in the subschema, so brute-forcing
              * the reverse-map for the "$rule->getUsedByAttrs()" data.*/
             $sattrs = $this->SchemaAttributes($method, $dn);
             if (is_array($sattrs)) {
                 foreach ($sattrs as $attr) {
                     $rule_key = strtolower($attr->getEquality());
                     if (isset($rules[$rule_key])) {
                         $rules[$rule_key]->addUsedByAttr($attr->getName(false));
                     }
                 }
             }
         }
         $return = $rules;
         # cache the schema to prevent multiple schema fetches from LDAP server
         set_cached_item($this->index, 'schema', 'matchingrules', $return);
     }
     if (DEBUG_ENABLED) {
         debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return);
     }
     return $return;
 }