Example #1
0
 public function getConnection($method, $path, $data = null, array $headers = array())
 {
     $start = microtime(true);
     $response = $this->client->getConnection($method, $path, $data, $headers);
     $duration = microtime(true) - $start;
     $this->requests[] = array('duration' => $duration, 'method' => $method, 'path' => rawurldecode($path), 'request' => $data, 'request_size' => strlen($data), 'response_status' => $response->status, 'response' => $response->body, 'response_headers' => $response->headers);
     $this->totalDuration += $duration;
     return $response;
 }
Example #2
0
 /**
  * Execute query
  *
  * @access public
  * @param  string    $baseDn
  * @param  string    $filter
  * @param  array     $attributes
  * @return Query
  */
 public function execute($baseDn, $filter, array $attributes)
 {
     $sr = ldap_search($this->client->getConnection(), $baseDn, $filter, $attributes);
     if ($sr === false) {
         return $this;
     }
     $entries = ldap_get_entries($this->client->getConnection(), $sr);
     if ($entries === false || count($entries) === 0 || $entries['count'] == 0) {
         return $this;
     }
     $this->entries = $entries;
     return $this;
 }
Example #3
0
 public function testConnectFailureWithTLS()
 {
     self::$functions->expects($this->once())->method('ldap_connect')->with($this->equalTo('my_ldap_server'), $this->equalTo(389))->will($this->returnValue('my_ldap_resource'));
     self::$functions->expects($this->once())->method('ldap_start_tls')->with($this->equalTo('my_ldap_resource'))->will($this->returnValue(false));
     $this->setExpectedException('\\Kanboard\\Core\\Ldap\\ClientException');
     $ldap = new Client();
     $this->assertNotEquals('my_ldap_resource', $ldap->getConnection('my_ldap_server', 389, true));
 }
Example #4
0
 /**
  * Checks if the passed client instance satisfies the required conditions
  * needed to initialize a monitor context.
  *
  * @param Client Client instance used by the context.
  */
 private function checkCapabilities(Client $client)
 {
     if (Helpers::isCluster($client->getConnection())) {
         throw new ClientException('Cannot initialize a monitor context over a cluster of connections');
     }
     if ($client->getProfile()->supportsCommand('monitor') === false) {
         throw new ClientException('The current profile does not support the MONITOR command');
     }
 }
Example #5
0
 /**
  * Checks if the passed client instance satisfies the required conditions
  * needed to initialize a Publish / Subscribe context.
  *
  * @param Client Client instance used by the context.
  */
 private function checkCapabilities(Client $client)
 {
     if (Helpers::isCluster($client->getConnection())) {
         throw new ClientException('Cannot initialize a PUB/SUB context over a cluster of connections');
     }
     $commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe');
     if ($client->getProfile()->supportsCommands($commands) === false) {
         throw new ClientException('The current profile does not support PUB/SUB related commands');
     }
 }
Example #6
0
 /**
  * Execute query
  *
  * @access public
  * @param  string    $baseDn
  * @param  string    $filter
  * @param  array     $attributes
  * @return Query
  */
 public function execute($baseDn, $filter, array $attributes)
 {
     if (DEBUG && $this->client->hasLogger()) {
         $this->client->getLogger()->debug('BaseDN=' . $baseDn);
         $this->client->getLogger()->debug('Filter=' . $filter);
         $this->client->getLogger()->debug('Attributes=' . implode(', ', $attributes));
     }
     $sr = ldap_search($this->client->getConnection(), $baseDn, $filter, $attributes);
     if ($sr === false) {
         return $this;
     }
     $entries = ldap_get_entries($this->client->getConnection(), $sr);
     if ($entries === false || count($entries) === 0 || $entries['count'] == 0) {
         return $this;
     }
     $this->entries = $entries;
     if (DEBUG && $this->client->hasLogger()) {
         $this->client->getLogger()->debug('NbEntries=' . $entries['count']);
     }
     return $this;
 }
Example #7
0
 public function removeClient(Client $client)
 {
     if ($this->disconnect_callback) {
         call_user_func_array($this->disconnect_callback, [$client]);
     }
     $buf = $client->getBuffer();
     $conn = $client->getConnection();
     event_buffer_disable($buf, EV_READ | EV_WRITE);
     event_buffer_free($buf);
     fclose($conn);
 }