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;
}