Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#2210 from weierophinne…
Browse files Browse the repository at this point in the history
…y/hotfix/remove-suppression-operator

Get rid of error suppression
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
48 changes: 39 additions & 9 deletions src/Collection/DefaultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Zend\Ldap;
use Zend\Ldap\Exception;
use Zend\Stdlib\ErrorHandler;

/**
* Zend\Ldap\Collection\DefaultIterator is the default collection iterator implementation
Expand Down Expand Up @@ -73,7 +74,10 @@ public function __construct(Ldap\Ldap $ldap, $resultId)
{
$this->ldap = $ldap;
$this->resultId = $resultId;
$this->itemCount = @ldap_count_entries($ldap->getResource(), $resultId);

ErrorHandler::start();
$this->itemCount = ldap_count_entries($ldap->getResource(), $resultId);
ErrorHandler::stop();
if ($this->itemCount === false) {
throw new Exception\LdapException($this->ldap, 'counting entries');
}
Expand All @@ -93,7 +97,10 @@ public function close()
{
$isClosed = false;
if (is_resource($this->resultId)) {
$isClosed = @ldap_free_result($this->resultId);
ErrorHandler::start();
$isClosed = ldap_free_result($this->resultId);
ErrorHandler::stop();

$this->resultId = null;
$this->current = null;
}
Expand Down Expand Up @@ -191,13 +198,26 @@ public function current()

$entry = array('dn' => $this->key());
$ber_identifier = null;
$name = @ldap_first_attribute(

ErrorHandler::start();
$name = ldap_first_attribute(
$this->ldap->getResource(), $this->current,
$ber_identifier
);
ErrorHandler::stop();

while ($name) {
$data = @ldap_get_values_len($this->ldap->getResource(), $this->current, $name);
unset($data['count']);
ErrorHandler::start();
$data = ldap_get_values_len($this->ldap->getResource(), $this->current, $name);
ErrorHandler::stop();

if (!$data) {
$data = array();
}

if (isset($data['count'])) {
unset($data['count']);
}

switch ($this->attributeNameTreatment) {
case self::ATTRIBUTE_TO_LOWER:
Expand All @@ -214,10 +234,13 @@ public function current()
break;
}
$entry[$attrName] = $data;
$name = @ldap_next_attribute(

ErrorHandler::start();
$name = ldap_next_attribute(
$this->ldap->getResource(), $this->current,
$ber_identifier
);
ErrorHandler::stop();
}
ksort($entry, SORT_LOCALE_STRING);
return $entry;
Expand All @@ -236,7 +259,10 @@ public function key()
$this->rewind();
}
if (is_resource($this->current)) {
$currentDn = @ldap_get_dn($this->ldap->getResource(), $this->current);
ErrorHandler::start();
$currentDn = ldap_get_dn($this->ldap->getResource(), $this->current);
ErrorHandler::stop();

if ($currentDn === false) {
throw new Exception\LdapException($this->ldap, 'getting dn');
}
Expand All @@ -259,7 +285,9 @@ public function next()
$code = 0;

if (is_resource($this->current) && $this->itemCount > 0) {
$this->current = @ldap_next_entry($this->ldap->getResource(), $this->current);
ErrorHandler::start();
$this->current = ldap_next_entry($this->ldap->getResource(), $this->current);
ErrorHandler::stop();
if ($this->current === false) {
$msg = $this->ldap->getLastError($code);
if ($code === Exception\LdapException::LDAP_SIZELIMIT_EXCEEDED) {
Expand All @@ -284,7 +312,9 @@ public function next()
public function rewind()
{
if (is_resource($this->resultId)) {
$this->current = @ldap_first_entry($this->ldap->getResource(), $this->resultId);
ErrorHandler::start();
$this->current = ldap_first_entry($this->ldap->getResource(), $this->resultId);
ErrorHandler::stop();
if ($this->current === false
&& $this->ldap->getLastErrorCode() > Exception\LdapException::LDAP_SUCCESS
) {
Expand Down
6 changes: 5 additions & 1 deletion src/Converter/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use DateTime;
use DateTimeZone;
use Zend\Stdlib\ErrorHandler;

/**
* Zend\Ldap\Converter is a collection of useful LDAP related conversion functions.
Expand Down Expand Up @@ -382,7 +383,10 @@ public static function fromLdapBoolean($value)
*/
public static function fromLdapUnserialize($value)
{
$v = @unserialize($value);
ErrorHandler::start(E_NOTICE);
$v = unserialize($value);
ErrorHandler::stop();

if (false === $v && $value != 'b:0;') {
throw new Exception\UnexpectedValueException('The given value could not be unserialized');
}
Expand Down
6 changes: 4 additions & 2 deletions src/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls
/* Only OpenLDAP 2.2 + supports URLs so if SSL is not requested, just
* use the old form.
*/
$resource = ($useUri) ? @ldap_connect($this->connectString) : @ldap_connect($host, $port);
ErrorHandler::start();
$resource = ($useUri) ? ldap_connect($this->connectString) : ldap_connect($host, $port);
ErrorHandler::stop();

if (is_resource($resource) === true) {
$this->resource = $resource;
Expand All @@ -736,7 +738,7 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls
if ($networkTimeout) {
ldap_set_option($resource, LDAP_OPT_NETWORK_TIMEOUT, $networkTimeout);
}
if ($useSsl || !$useStartTls || @ldap_start_tls($resource)) {
if ($useSsl || !$useStartTls || ldap_start_tls($resource)) {
ErrorHandler::stop();
return $this;
}
Expand Down

0 comments on commit 8dbf37e

Please sign in to comment.