Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
ModulesClassesFunctions
 

Class Reference

class ldap extends obj

Helix obj ldap
Hide Inherited MembersHelix Core
Description
No description.
 
Constants
No constants.
 
Properties
protected_connection[ ldap ]
protected_dirty[ obj ]
protected_dn[ ldap ]
protected_password[ ldap ]
protected_properties[ ldap ]
publicproperty_objects_array[ obj ]
protected_secure[ ldap ]
protected_server[ ldap ]
protected_username[ ldap ]
 
Methods
publicadd ( dn , properties )[ ldap ]
Parameters
requireddn
requiredproperties
Code
112  public function add($__dn, $__properties)
113  {
114      $this->_connect();
115      $this->_bind();
116      $attributes = array();
117      foreach ($__properties as $k=>$v)
118      {
119          if (is_array($v))
120          {
121              foreach ($v as $kk=>$vv)
122              {
123                  $attributes[$k][$kk] = strlen($vv)==0 ? " " : $vv;
124              }
125          }
126          else
127          {
128              $attributes[$k] = strlen($v)==0 ? " " : $v;
129          }
130      }
131      $add = ldap_add($this->connection, $__dn, $attributes);
132      $this->_disconnect();
133      return $add;
134  }
private_bind ( )[ ldap ]
Parameters
No parameters for this method
Code
033  private function _bind()
034  {
035      if (ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3))
036      {
037          return ldap_bind($this->connection, $this->username, $this->password);
038      }
039  }
private_connect ( )[ ldap ]
Parameters
No parameters for this method
Code
021  private function _connect()
022  {
023      $host = ($this->secure ? "ldaps://" : "ldap://") . $this->server;
024      $this->connection = ldap_connect($host);
025      return $this->connection;
026  }
public__construct ( server , dn , username , password )[ ldap ]
Parameters
optionalserver
optionaldn
optionalusername
optionalpassword
Code
012  public function __construct($__server=null, $__dn=null, $__username=null, $__password=null)
013  {
014      $this->server = is_null($__server) ? LDAP_SERVER : $__server;
015      $this->dn = is_null($__dn) ? LDAP_DSN : $__dn;
016      $this->username = is_null($__username) ? LDAP_DOMAIN. "\\" . LDAP_USER : $__username;
017      $this->password = is_null($__password) ? LDAP_PASSWORD : $__password;       
018      $this->secure = false;
019  }
private_disconnect ( )[ ldap ]
Parameters
No parameters for this method
Code
028  private function _disconnect()
029  {
030      return ldap_close($this->connection);
031  }
public staticencode_password ( password )[ ldap ]
Parameters
requiredpassword
Code
164  public static function encode_password($__password)
165  {
166      $password = "\"$__password\"";
167      $encoded = "";
168      for ($i=0; $i<strlen($password); $i++)
169      {
170          $encoded .= "{$password{$i}}\000";
171      }
172      return $encoded;
173  }
public__get ( p )[ obj ]
Parameters
requiredp
Code
007  public function __get($p)
008  {
009      $methods = get_class_methods($this);
010      $properties = get_object_vars($this);
011      if (in_array("get_$p",$methods))
012      {
013          return $this->{"get_$p"}();
014      }
015      else if (array_key_exists("_$p",$properties))
016      {
017          return $this->{"_$p"};
018      }
019      else if (in_array("get_" . substr($p,strpos($p,"_")+1), $methods))
020      {
021          return $this->{"get_" . substr($p,strpos($p,"_")+1)}(substr($p,0,strpos($p,"_")));
022      }
023      else
024      {
025          trigger_error("This object [" . get_class($this) . ":$this->id] has no private property '_$p' for the requested public property '$p'",E_USER_WARNING);
026          return null;
027      }
028  }
publicget_array ( )[ obj ]
Parameters
No parameters for this method
Code
096  public function get_array()
097  {
098      return get_object_vars($this);
099  }
publicget_classname ( )[ obj ]
Parameters
No parameters for this method
Code
086  public function get_classname()
087  {
088      return get_class($this);
089  }
publicget_dirty ( )[ obj ]
Parameters
No parameters for this method
Code
063  public function get_dirty()
064  {
065      if ($this->id === 0)
066      {
067          $this->_dirty = true;
068      }
069      else
070      {
071          foreach (get_object_vars($this) as $k=>$v)
072          {
073              if ($this->_dirty)
074              {
075                  break;
076              }
077              if (preg_match('/_dirty$/',$k))
078              {
079                  $this->_dirty = $this->_dirty || $v;
080              }
081          }
082      }
083      return $this->_dirty;
084  }
publicget_json ( )[ obj ]
Parameters
No parameters for this method
Code
101  public function get_json()
102  {
103      $class = new ReflectionClass($this->classname);
104      $methods = $class->getMethods();
105      usort($methods,"sort_reflection_objects");
106      $accessors = array();
107      foreach ($methods as $index=>$method)
108      {
109          $declarer = $method->getDeclaringClass()->name;
110          if (preg_match('/^(get|set|)_(.+)$/',$method->name,$matches))
111          {
112              $accessor = $matches[2];
113              $getset = $matches[1];
114              eval("\$accessors[\$accessor] = \$this->".$accessor.";");
115          }
116      }
117      //return json_encode($this->get_array());
118      return json_encode($accessors);
119  }
publicget_properties ( )[ ldap ]
Parameters
No parameters for this method
Code
136  public function get_properties()
137  {
138      return array(
139          "dn",
140          "cn",
141          "givenname",
142          "sn",
143          "samaccountname",
144          "extensionattribute1",
145          "extensionattribute2",
146          "extensionattribute3",
147          "extensionattribute4",
148          "extensionattribute5",
149          "extensionattribute6",
150          "extensionattribute7",
151          "extensionattribute8",
152          "department",
153          "division",
154          "useraccountcontrol",
155          "employeeid",
156          "memberof",
157          "scriptpath",
158          "employeetype",
159          "company",
160          "mail"
161      );
162  }
protectedget_string ( )[ obj ]
Parameters
No parameters for this method
Code
091  protected function get_string()
092  {
093      return method_exists($this,"__toString") ? $this->__toString() : null;
094  }
publicmodify ( dn , properties )[ ldap ]
Parameters
requireddn
requiredproperties
Code
099  public function modify($__dn, $__properties)
100  {
101      $this->_connect();
102      $this->_bind();
103      foreach ($__properties as $k=>$v)
104      {
105          $__properties[$k] = strlen($v)==0 ? " " : $v;
106      }
107      $modify = ldap_modify($this->connection, $__dn, $__properties);
108      $this->_disconnect();
109      return $modify;
110  }
publicrename ( old_dn , new_dn )[ ldap ]
Parameters
requiredold_dn
requirednew_dn
Code
088  public function rename($__old_dn, $__new_dn)
089  {
090      $this->_connect();
091      $this->_bind();
092      preg_match('/^(cn=[^,]+),(.+)$/i',$__new_dn,$matches);
093      list($dn,$cn,$ou) = $matches;
094      $rename = ldap_rename($this->connection, $__old_dn, $cn, $ou, true);
095      $this->_disconnect();
096      return $rename;
097  }
publicsearch ( query , properties )[ ldap ]
public__set ( p , v )[ obj ]
Parameters
requiredp
requiredv
Code
030  public function __set($p,$v)
031  {
032      $methods = get_class_methods($this);
033      $properties = get_object_vars($this);
034      if (in_array("set_$p",$methods))
035      {
036          $this->{"set_$p"}($v);
037      }
038      else if (array_key_exists("_$p",$properties))
039      {
040          if (!preg_match('/_dirty$/',$p) && property_exists($this,"_{$p}_dirty"))
041          {
042              if (is_object($this->{"_$p"}))
043              {
044                  $this->{"_$p"}->dirty = true;
045              }
046              else
047              {
048                  $this->{"_{$p}_dirty"} = $this->{$p}==$v ? false : true;
049              }
050          }
051          $this->{"_$p"} = $v;
052      }
053      else if (in_array("set_" . substr($p,strpos($p,"_")+1), $methods))
054      {
055          $this->{"set_" . substr($p,strpos($p,"_")+1)}($v,substr($p,0,strpos($p,"_")));
056      }
057      else
058      {
059          trigger_error("This object [" . get_class($this) . ":$this->id] has no private property '_$p' for the requested public property '$p'",E_USER_WARNING);
060      }
061  }
 
Accessors
publicarray[ obj ]
Code
096  public function get_array()
097  {
098      return get_object_vars($this);
099  }
publicclassname[ obj ]
Code
086  public function get_classname()
087  {
088      return get_class($this);
089  }
publicdirty[ obj ]
Code
063  public function get_dirty()
064  {
065      if ($this->id === 0)
066      {
067          $this->_dirty = true;
068      }
069      else
070      {
071          foreach (get_object_vars($this) as $k=>$v)
072          {
073              if ($this->_dirty)
074              {
075                  break;
076              }
077              if (preg_match('/_dirty$/',$k))
078              {
079                  $this->_dirty = $this->_dirty || $v;
080              }
081          }
082      }
083      return $this->_dirty;
084  }
publicjson[ obj ]
Code
101  public function get_json()
102  {
103      $class = new ReflectionClass($this->classname);
104      $methods = $class->getMethods();
105      usort($methods,"sort_reflection_objects");
106      $accessors = array();
107      foreach ($methods as $index=>$method)
108      {
109          $declarer = $method->getDeclaringClass()->name;
110          if (preg_match('/^(get|set|)_(.+)$/',$method->name,$matches))
111          {
112              $accessor = $matches[2];
113              $getset = $matches[1];
114              eval("\$accessors[\$accessor] = \$this->".$accessor.";");
115          }
116      }
117      //return json_encode($this->get_array());
118      return json_encode($accessors);
119  }
publicproperties[ ldap ]
Code
136  public function get_properties()
137  {
138      return array(
139          "dn",
140          "cn",
141          "givenname",
142          "sn",
143          "samaccountname",
144          "extensionattribute1",
145          "extensionattribute2",
146          "extensionattribute3",
147          "extensionattribute4",
148          "extensionattribute5",
149          "extensionattribute6",
150          "extensionattribute7",
151          "extensionattribute8",
152          "department",
153          "division",
154          "useraccountcontrol",
155          "employeeid",
156          "memberof",
157          "scriptpath",
158          "employeetype",
159          "company",
160          "mail"
161      );
162  }
publicstring[ obj ]
Code
091  protected function get_string()
092  {
093      return method_exists($this,"__toString") ? $this->__toString() : null;
094  }
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads