Author: Chad Sikorra (Chad.Sikorra@gmail.com)
Example #1
0
 /**
  * Validate a control directive and get the value for the control and the criticality.
  *
  * @param string $value
  * @return LdapControl
  * @throws LdifParserException
  */
 protected function getLdapControl($value)
 {
     $values = explode(' ', $value);
     // This should never happen, but it seems better to cover it in case...
     if (empty($values) || $values === false) {
         $this->throwException(sprintf('Expecting a LDAP control but got "%s"', $value));
     }
     // The first value should be an actual OID...
     if (!preg_match(LdapUtilities::MATCH_OID, $values[0])) {
         $this->throwException(sprintf('The control directive has an invalid OID format "%s"', $values[0]));
     }
     $control = new LdapControl($values[0]);
     if (isset($values[1])) {
         $control->setCriticality($this->getBoolFromStringBool($values[1]));
     }
     if (isset($values[2])) {
         $control->setValue($values[2]);
     }
     return $control;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function setControl(LdapControl $control)
 {
     // To set a a server control we must first be bound...
     if (!$this->isBound()) {
         $this->connect();
     }
     if (!@ldap_set_option($this->connection, LDAP_OPT_SERVER_CONTROLS, [$control->toArray()]) && $control->getCriticality()) {
         throw new LdapConnectionException(sprintf('Unable to set control for OID "%s".', $control->getOid()));
     }
 }