Quindi ho il seguente codice, che si connette e quindi si collega a un server LDAP.
La domanda è nel primo metodo.
public function getUsers() // This is the method in question
{
if( $this->connect()->bind() ) {
ldap_query(self::$connection) // Here, should it be aware that class succesfully loaded
// the connection, or should the bind() method return the resource?
}
}
public function connect()
{
self::$connection = ldap_connect($this->host);
if( ! self::$connection ) {
throw new \CHttpException(503, 'No se puede establecer una conexión con el servidor '.$this->host);
}
foreach( $this->options as $option => $value ) {
ldap_set_option(self::$connection, constant($option), $value);
}
return $this;
}
public function bind()
{
$ldapbind = ldap_bind(self::$connection, $this->username.'@'.$this->domain, $this->password);
if( ! $ldapbind ) {
throw new \CHttpException(503, 'No se puede enlazar con el servidor: '.ldap_error(self::$connection));
}
return true;
}