Horde_Ldap::schema PHP Method

schema() public method

Returns a schema object
public schema ( string $dn = null ) : Horde_Ldap_Schema
$dn string Subschema entry dn.
return Horde_Ldap_Schema Horde_Ldap_Schema object
    public function schema($dn = null)
    {
        /* If a schema caching object is registered, we use that to fetch a
         * schema object. */
        $key = 'Horde_Ldap_Schema_' . md5(serialize(array($this->_config['hostspec'], $this->_config['port'], $dn)));
        if (!$this->_schema && $this->_config['cache']) {
            $schema = $this->_config['cache']->get($key, $this->_config['cachettl']);
            if ($schema) {
                $this->_schema = @unserialize($schema);
            }
        }
        /* Fetch schema, if not tried before and no cached version available.
         * If we are already fetching the schema, we will skip fetching. */
        if (!$this->_schema) {
            /* Store a temporary error message so subsequent calls to schema()
             * can detect that we are fetching the schema already. Otherwise we
             * will get an infinite loop at Horde_Ldap_Schema. */
            $this->_schema = new Horde_Ldap_Exception('Schema not initialized');
            $this->_schema = new Horde_Ldap_Schema($this, $dn);
            /* If schema caching is active, advise the cache to store the
             * schema. */
            if ($this->_config['cache']) {
                $this->_config['cache']->set($key, serialize($this->_schema), $this->_config['cachettl']);
            }
        }
        if ($this->_schema instanceof Horde_Ldap_Exception) {
            throw $this->_schema;
        }
        return $this->_schema;
    }

Usage Example

コード例 #1
0
ファイル: Entry.php プロジェクト: raz0rsdge/horde
 /**
  * Sets the internal attributes array.
  *
  * This method fetches the values for the attributes from the server.  The
  * attribute syntax will be checked so binary attributes will be returned
  * as binary values.
  *
  * Attributes may be passed directly via the $attributes parameter to setup
  * this entry manually. This overrides attribute fetching from the server.
  *
  * @param array $attributes Attributes to set for this entry.
  */
 protected function _loadAttributes(array $attributes = null)
 {
     /* Fetch attributes from the server. */
     if (is_null($attributes) && is_resource($this->_entry) && is_resource($this->_link)) {
         /* Fetch schema. */
         if ($this->_ldap instanceof Horde_Ldap) {
             try {
                 $schema = $this->_ldap->schema();
             } catch (Horde_Ldap_Exception $e) {
                 $schema = null;
             }
         }
         /* Fetch attributes. */
         $attributes = array();
         for ($attr = @ldap_first_attribute($this->_link, $this->_entry); $attr; $attr = @ldap_next_attribute($this->_link, $this->_entry)) {
             /* Standard function to fetch value. */
             $func = 'ldap_get_values';
             /* Try to get binary values as binary data. */
             if ($schema instanceof Horde_Ldap_Schema && $schema->isBinary($attr)) {
                 $func = 'ldap_get_values_len';
             }
             /* Fetch attribute value (needs error checking?) . */
             $attributes[$attr] = $func($this->_link, $this->_entry, $attr);
         }
     }
     /* Set attribute data directly, if passed. */
     if (is_array($attributes) && count($attributes) > 0) {
         if (isset($attributes['count']) && is_numeric($attributes['count'])) {
             unset($attributes['count']);
         }
         foreach ($attributes as $k => $v) {
             /* Attribute names should not be numeric. */
             if (is_numeric($k)) {
                 continue;
             }
             /* Map generic attribute name to real one. */
             $this->_map[Horde_String::lower($k)] = $k;
             /* Attribute values should be in an array. */
             if (false == is_array($v)) {
                 $v = array($v);
             }
             /* Remove the value count (comes from LDAP server). */
             if (isset($v['count'])) {
                 unset($v['count']);
             }
             $this->_attributes[$k] = $v;
         }
     }
     /* Save a copy for later use. */
     $this->_original = $this->_attributes;
 }
All Usage Examples Of Horde_Ldap::schema