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

Removes default dependency to Zend\StdLib #21

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -44,6 +44,7 @@ before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.5" ]]; then composer require --dev --no-update phpunit/phpunit ~4; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -14,15 +14,15 @@
},
"require": {
"php": ">=5.5",
"ext-ldap": "*",
"zendframework/zend-stdlib": "~2.5"
"ext-ldap": "*"
},
"require-dev": {
"zendframework/zend-config": "~2.5",
"zendframework/zend-eventmanager": "~2.5",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0",
"php-mock/php-mock-phpunit": "~0.3"
"php-mock/php-mock-phpunit": "~0.3",
"zendframework/zend-stdlib": "~2.5"
},
"suggest": {
"zendframework/zend-eventmanager": "Zend\\EventManager component"
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/DefaultIterator.php
Expand Up @@ -13,7 +13,7 @@
use Iterator;
use Zend\Ldap;
use Zend\Ldap\Exception;
use Zend\Stdlib\ErrorHandler;
use Zend\Ldap\ErrorHandler;

/**
* Zend\Ldap\Collection\DefaultIterator is the default collection iterator implementation
Expand Down
2 changes: 1 addition & 1 deletion src/Converter/Converter.php
Expand Up @@ -11,7 +11,7 @@

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

/**
* Zend\Ldap\Converter is a collection of useful LDAP related conversion functions.
Expand Down
100 changes: 100 additions & 0 deletions src/ErrorHandler.php
@@ -0,0 +1,100 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Ldap;

/**
* Handle Errors that might occur during execution of ldap_*-functions
*
* @package Zend\Ldap\ErrorHandler
*/
class ErrorHandler implements ErrorHandlerInterface
{
/**
* @var ErrorHandlerInterface The Errror-Handler instance
*/
protected static $errorHandler;

/**
* Start the Error-Handling
*
* You can specify which errors to handle by passing a combination of PHPs
* Error-constants like E_WARNING or E_NOTICE or E_WARNING ^ E_DEPRECATED
*
* @param int $level The Error-level(s) to handle by this ErrorHandler
*
* @return void
*/
public static function start($level = E_WARNING)
{
self::getErrorHandler()->startErrorHandling($level);
}

/**
* @param bool|false $throw
*
* @return mixed
*/
public static function stop($throw = false)
{
return self::getErrorHandler()->stopErrorHandling($throw);
}

/**
* Get an error handler
*
* @return ErrorHandlerInterface
*/
protected static function getErrorHandler()
{
if (! self::$errorHandler && ! self::$errorHandler instanceof ErrorHandlerInterface) {
self::$errorHandler = new self();
}

return self::$errorHandler;
}

/**
* This method does nothing on purpose.
*
* @param int $level
*
* @see ErrorHandlerInterface::startErrorHandling()
* @return void
*/
public function startErrorHandling($level = E_WARNING)
{
// Do nothing!
}

/**
* This method does nothing on purpose.
*
* @param bool|false $throw
*
* @see ErrorHandlerInterface::stopErrorHandling()
* @return void
*/
public function stopErrorHandling($throw = false)
{
// Do nothing;
}

/**
* Set the error handler to be used
*
* @param ErrorHandlerInterface $errorHandler
*
* @return void
*/
public static function setErrorHandler(ErrorHandlerInterface $errorHandler)
{
self::$errorHandler = $errorHandler;
}
}
39 changes: 39 additions & 0 deletions src/ErrorHandlerInterface.php
@@ -0,0 +1,39 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Ldap;

/**
* Handle Errors that might occur during execution of ldap_*-functions
*
* @package Zend\Ldap\ErrorHandler
*/
interface ErrorHandlerInterface
{
/**
* Start the ErrorHandling-process
*
* @param int $level
*
* @return void
*/
public function startErrorHandling($level = E_WARNING);

/**
* Stop the error-handling process.
*
* The parameter <var>$throw</var> handles whether the captured errors shall
* be thrown as Exceptions or not
*
* @param bool|false $throw
*
* @return mixed
*/
public function stopErrorHandling($throw = false);
}
1 change: 0 additions & 1 deletion src/Ldap.php
Expand Up @@ -11,7 +11,6 @@

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

class Ldap
{
Expand Down
42 changes: 42 additions & 0 deletions test/ErrorHandler.php
@@ -0,0 +1,42 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Ldap;

use Zend\Ldap\ErrorHandlerInterface;
use Zend\Stdlib\ErrorHandler as DefaultErrorHandler;

class ErrorHandler implements ErrorHandlerInterface
{
/**
* Start the ErrorHandling-process
*
* @param int $level
*
* @return void
*/
public function startErrorHandling($level = E_WARNING)
{
DefaultErrorHandler::start($level);
}

/**
* Stop the error-handling process.
* The parameter <var>$throw</var> handles whether the captured errors shall
* be thrown as Exceptions or not
*
* @param bool|false $throw
*
* @return mixed
*/
public function stopErrorHandling($throw = false)
{
return DefaultErrorHandler::stop($throw);
}
}
6 changes: 6 additions & 0 deletions test/bootstrap.php
Expand Up @@ -21,11 +21,17 @@
unset($phpUnitVersion);
}


/**
* Setup autoloading
*/
require __DIR__ . '/../vendor/autoload.php';

/**
* Setting the Zend\StdLib/ErrorHandler as default ErrorHandler
*/
Zend\Ldap\ErrorHandler::setErrorHandler(new ZendTest\Ldap\ErrorHandler());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the default ErrorHandler does nothing at all but the tests seem to depend on error-suppression I've added that one to get the tests running under the same conditions as before. I was thinking of adding that line to src/Ldap.php (at the very end) so that that's set as default error handler and users can overwrite that with their own implementation. On the other hand that would mean that the dependency to Zend\StdLib\ErrorHandler would not be eliminated.


/**
* Start output buffering, if enabled
*/
Expand Down