/** * Gets an associative array of ObjectClass objects for the specified * server. Each array entry's key is the name of the objectClass * in lower-case and the value is an ObjectClass object. * * @param string $dn (optional) It is easier to fetch schema if a DN is provided * which defines the subschemaSubEntry attribute (all entries should). * * @return array An array of ObjectClass objects. * * @see ObjectClass * @see getSchemaObjectClass */ public function SchemaObjectClasses($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', 'objectclasses')) { if (DEBUG_ENABLED) { debug_log('Returning CACHED [%s] (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $this->index, 'objectclasses'); } return $return; } $raw = $this->getRawSchema($method, 'objectclasses', $dn); if ($raw) { # Build the array of objectClasses $return = array(); foreach ($raw as $line) { if (is_null($line) || !strlen($line)) { continue; } $object_class = new ObjectClass($line, $this); $return[$object_class->getName()] = $object_class; } # Now go through and reference the parent/child relationships foreach ($return as $oclass) { foreach ($oclass->getSupClasses() as $parent_name) { if (isset($return[strtolower($parent_name)])) { $return[strtolower($parent_name)]->addChildObjectClass($oclass->getName(false)); } } } ksort($return); # cache the schema to prevent multiple schema fetches from LDAP server set_cached_item($this->index, 'schema', 'objectclasses', $return); } if (DEBUG_ENABLED) { debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return); } return $return; }
/** * Gets an associative array of ObjectClass objects for the specified * server. Each array entry's key is the name of the objectClass * in lower-case and the value is an ObjectClass object. * * @param string $dn (optional) It is easier to fetch schema if a DN is provided * which defines the subschemaSubEntry attribute (all entries should). * * @return array An array of ObjectClass objects. * * @see ObjectClass * @see getSchemaObjectClass */ function SchemaObjectClasses($dn = '') { debug_log('%s::SchemaObjectClasses(): Entered with (%s)', 25, get_class($this), $dn); # Set default return $return = null; if ($return = get_cached_item($this->server_id, 'schema', 'objectclasses')) { debug_log('%s::SchemaObjectClasses(): Returning CACHED [%s] (%s)', 25, get_class($this), $this->server_id, 'objectclasses'); return $return; } $raw_oclasses = $this->getRawSchema('objectclasses', $dn); if ($raw_oclasses) { # build the array of objectClasses $return = array(); foreach ($raw_oclasses as $class_string) { if (is_null($class_string) || !strlen($class_string)) { continue; } $object_class = new ObjectClass($class_string, $this); $return[strtolower($object_class->getName())] = $object_class; } # Now go through and reference the parent/child relationships foreach ($return as $oclass) { foreach ($oclass->getSupClasses() as $parent_name) { if (isset($return[strtolower($parent_name)])) { $return[strtolower($parent_name)]->addChildObjectClass($oclass->getName()); } } } ksort($return); # cache the schema to prevent multiple schema fetches from LDAP server set_cached_item($this->server_id, 'schema', 'objectclasses', $return); } debug_log('%s::SchemaObjectClasses(): Returning (%s)', 25, get_class($this), $return); return $return; }
function get_schema_objectclasses($server_id) { // cache the schema to prevent multiple schema fetches from LDAP server static $cache = array(); if (isset($cache[$server_id])) { //echo "Using oclass cache.<br />"; return $cache[$server_id]; } $ds = pla_ldap_connect($server_id); if (!$ds) { return false; } // try with the standard DN $result = @ldap_read($ds, 'cn=subschema', '(objectClass=*)', array('objectclasses'), 0, 200, 0, LDAP_DEREF_ALWAYS); if (!$result) { // try again, with a different schema DN $result = @ldap_read($ds, 'cn=schema', '(objectClass=*)', array('objectclasses'), 0, 200, 0, LDAP_DEREF_ALWAYS); } if (!$result) { // give up return false; } $raw_oclasses = @ldap_get_entries($ds, $result); // build the array of objectClasses $object_classes = array(); for ($i = 0; $i < $raw_oclasses[0]['objectclasses']['count']; $i++) { $class_string = $raw_oclasses[0]["objectclasses"][$i]; if ($class_string == null || 0 == strlen($class_string)) { continue; } $object_class = new ObjectClass($class_string); $name = $object_class->getName(); $key = strtolower($name); $object_classes[$key] = $object_class->toAssoc(); } // go back and add any inherited MUST/MAY attrs to each objectClass foreach ($object_classes as $name => $object_class) { $sup_classes = $object_class['sup']; $must = $object_class['must_attrs']; $may = $object_class['may_attrs']; foreach ($sup_classes as $sup_class) { add_sup_class_attrs($name, $sup_class, $object_classes, $must, $may); } $object_classes[$name]['must_attrs'] = $must; $object_classes[$name]['may_attrs'] = $may; } ksort($object_classes); // cache the schema to prevent multiple schema fetches from LDAP server $cache[$server_id] = $object_classes; return $object_classes; }