本文整理汇总了PHP中restore_error_handler函数的典型用法代码示例。如果您正苦于以下问题:PHP restore_error_handler函数的具体用法?PHP restore_error_handler怎么用?PHP restore_error_handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了restore_error_handler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertErrorsAreTriggered
/**
* @param int $expectedType Expected triggered error type (pass one of PHP's E_* constants)
* @param string[] $expectedMessages Expected error messages
* @param callable $testCode A callable that is expected to trigger the error messages
*/
public static function assertErrorsAreTriggered($expectedType, $expectedMessages, $testCode)
{
if (!is_callable($testCode)) {
throw new \InvalidArgumentException(sprintf('The code to be tested must be a valid callable ("%s" given).', gettype($testCode)));
}
$e = null;
$triggeredMessages = array();
try {
$prevHandler = set_error_handler(function ($type, $message, $file, $line, $context) use($expectedType, &$triggeredMessages, &$prevHandler) {
if ($expectedType !== $type) {
return null !== $prevHandler && call_user_func($prevHandler, $type, $message, $file, $line, $context);
}
$triggeredMessages[] = $message;
});
call_user_func($testCode);
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
restore_error_handler();
if (null !== $e) {
throw $e;
}
\PHPUnit_Framework_Assert::assertCount(count($expectedMessages), $triggeredMessages);
foreach ($triggeredMessages as $i => $message) {
\PHPUnit_Framework_Assert::assertContains($expectedMessages[$i], $message);
}
}
示例2: setEnvVariables
/**
* Set app environment variables
*
* @param string $root
* @return void
*/
public static function setEnvVariables($root = '/')
{
$configs = null;
// Set custom handler to catch errors as exceptions
set_error_handler(create_function('$severity, $message, $file, $line', 'throw new \\ErrorException($message, $severity, $severity, $file, $line);'));
if (file_exists($root . '/.dev.env') && is_readable($root . '/.dev.env')) {
$configs = file_get_contents($root . '/.dev.env');
} else {
if (file_exists($root . '/.dist.env') && is_readable($root . '/.dist.env')) {
$configs = file_get_contents($root . '/.dist.env');
} else {
if (file_exists($root . '/.test.env') && is_readable($root . '/.test.env')) {
$configs = file_get_contents($root . '/.test.env');
} else {
if (file_exists($root . '/.env') && is_readable($root . '/.env')) {
$configs = file_get_contents($root . '/.env');
} else {
throw new NotFoundException('No configuration file found.');
}
}
}
}
if (false === $configs || null !== error_get_last()) {
throw new UnreadableException('Configuration not readable.');
}
// Restore original error handler
restore_error_handler();
$configs = explode("\n", trim($configs));
array_map(function ($config) {
// Remove whitespaces
$config = preg_replace('(\\s+)', '', $config);
// Add as environment variables
putenv($config);
}, $configs);
}
示例3: lock
/**
* Lock the resource
*
* @param bool $blocking wait until the lock is released
* @return bool Returns true if the lock was acquired, false otherwise
* @throws IOException If the lock file could not be created or opened
*/
public function lock($blocking = false)
{
if ($this->handle) {
return true;
}
// Silence both userland and native PHP error handlers
$errorLevel = error_reporting(0);
set_error_handler('var_dump', 0);
if (!($this->handle = fopen($this->file, 'r'))) {
if ($this->handle = fopen($this->file, 'x')) {
chmod($this->file, 0444);
} elseif (!($this->handle = fopen($this->file, 'r'))) {
usleep(100);
// Give some time for chmod() to complete
$this->handle = fopen($this->file, 'r');
}
}
restore_error_handler();
error_reporting($errorLevel);
if (!$this->handle) {
$error = error_get_last();
throw new IOException($error['message'], 0, null, $this->file);
}
// On Windows, even if PHP doc says the contrary, LOCK_NB works, see
// https://bugs.php.net/54129
if (!flock($this->handle, LOCK_EX | ($blocking ? 0 : LOCK_NB))) {
fclose($this->handle);
$this->handle = null;
return false;
}
return true;
}
示例4: configure_environment
/**
* Configures the environment for testing
*
* Does the following:
*
* * Loads the phpunit framework (for the web ui)
* * Restores exception phpunit error handlers (for cli)
* * registeres an autoloader to load test files
*/
public static function configure_environment($do_whitelist = TRUE, $do_blacklist = TRUE)
{
// During a webui request we need to manually load PHPUnit
if (!class_exists('PHPUnit_Util_Filter', FALSE) and !function_exists('phpunit_autoload')) {
try {
include_once 'PHPUnit/Autoload.php';
} catch (ErrorException $e) {
include_once 'PHPUnit/Framework.php';
}
}
// Allow PHPUnit to handle exceptions and errors
if (Kohana::$is_cli) {
restore_exception_handler();
restore_error_handler();
}
spl_autoload_register(array('Kohana_Tests', 'autoload'));
Kohana_Tests::$cache = ($cache = Kohana::cache('unittest_whitelist_cache')) === NULL ? array() : $cache;
// As of PHPUnit v3.5 there are slight differences in the way files are black|whitelisted
self::$phpunit_v35 = function_exists('phpunit_autoload');
$config = Kohana::config('unittest');
if ($do_whitelist and $config->use_whitelist) {
self::whitelist();
}
if ($do_blacklist and count($config['blacklist'])) {
Kohana_Tests::blacklist($config->blacklist);
}
}
示例5: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
set_error_handler(array('Symfony\\Component\\Form\\Test\\DeprecationErrorHandler', 'handleBC'));
$resolver->setDefaults($this->getDefaultOptions(array()));
$resolver->addAllowedValues($this->getAllowedOptionValues(array()));
restore_error_handler();
}
示例6: clean
/**
* Stop all active handler
*
* @return void
*/
public static function clean()
{
if (static::$stack) {
restore_error_handler();
}
static::$stack = array();
}
示例7: testAppNonRepo
public function testAppNonRepo()
{
$app = new Application('Test', '1.2.3');
$app->setAutoExit(false);
restore_error_handler();
$this->assertInstanceOf('KevinGH\\Amend\\Command', $app->get('update'));
}
示例8: getContentHtml
public static function getContentHtml($title, $leadOnly)
{
$url = 'http://reading-web-research.wmflabs.org/api/slim/';
if ($leadOnly) {
$url .= 'lead/';
}
$url .= rawurlencode($title);
set_error_handler(function () {
throw new Exception('Error at endpoint.');
}, E_WARNING);
$resp = file_get_contents($url, false);
restore_error_handler();
$json = json_decode($resp);
$sections = $json->{'sections'};
if ($leadOnly) {
$content = $sections[0]->{'content'};
$continue = Html::element('a', array('id' => 'loot-fold', 'style' => 'clear:both; display: block;', 'href' => '?full=1#continue-from'), 'Continue reading...');
$content .= $continue;
} else {
$content = '';
foreach ($sections as $key => $section) {
if ($key > 0) {
$content .= '<h2>' . $section->{'title'} . '</h2>';
}
$content .= $section->{'content'};
if ($key === 0) {
$content .= '<div id="continue-from"></div>';
}
}
}
return $content;
}
示例9: __invoke
public function __invoke($data)
{
set_error_handler($this->generateErrorHandler($data));
$parsed = yaml_emit($data);
restore_error_handler();
return $parsed;
}
示例10: process
/**
* Process one expression an enqueue it using the ExprBuilder instance.
*
* @param ExprBuilder $builder
* @param string $field
* @param string $expression
* @param string $value
*
* @return ExprBuilder
*
* @throws ParserException
*/
public function process(ExprBuilder $builder, $field, $expression, $value)
{
if (!Expr::isValidExpression($expression)) {
throw new ParserException(sprintf('The expression "%s" is not allowed or not exists.', $expression));
}
switch ($expression) {
case 'between':
set_error_handler(function () use($value) {
throw new ParserException(sprintf('The value of "between" expression "%s" is not valid.', $value));
});
list($from, $to) = explode('-', $value);
restore_error_handler();
return $builder->between($field, $from, $to);
case 'paginate':
set_error_handler(function () use($value) {
throw new ParserException(sprintf('The value of "paginate" expression "%s" is not valid.', $value));
});
list($currentPageNumber, $maxResultsPerPage) = explode('-', $value);
restore_error_handler();
return $builder->paginate($currentPageNumber, $maxResultsPerPage);
case 'or':
return $builder->orx($value);
default:
return $builder->{$expression}($field, $value);
}
}
示例11: connect
/**
* Connect to an Oracle database using a persistent connection
*
* New instances of this class will use the same connection across multiple requests.
*
* @param string $username
* @param string $password
* @param string $connectionString
* @param string $characterSet
* @param int $sessionMode
* @return resource
* @see http://php.net/manual/en/function.oci-pconnect.php
*/
protected function connect($username, $password, $connectionString = null, $characterSet = null, $sessionMode = null)
{
set_error_handler($this->getErrorHandler());
$connection = oci_pconnect($username, $password, $connectionString, $characterSet, $sessionMode);
restore_error_handler();
return $connection;
}
示例12: configure_enviroment
/**
* Configures the enviroment for testing
*
* Does the following:
*
* * Loads the phpunit framework (for the web ui)
* * Restores exception phpunit error handlers (for cli)
* * registeres an autoloader to load test files
*/
public static function configure_enviroment($do_whitelist = TRUE, $do_blacklist = TRUE)
{
if (!class_exists('PHPUnit_Util_Filter', FALSE)) {
// Make sure the PHPUnit classes are available
require_once 'PHPUnit/Framework.php';
}
if (Kohana::$is_cli) {
restore_exception_handler();
restore_error_handler();
}
spl_autoload_register(array('Kohana_Tests', 'autoload'));
Kohana_Tests::$cache = ($cache = Kohana::cache('phpunit_whitelist_cache')) === NULL ? array() : $cache;
$config = Kohana::config('phpunit');
if ($do_whitelist and $config->use_whitelist) {
self::whitelist();
}
if ($do_blacklist and count($config['blacklist'])) {
foreach ($config->blacklist as $item) {
if (is_dir($item)) {
PHPUnit_Util_Filter::addDirectoryToFilter($item);
} else {
PHPUnit_Util_Filter::addFileToFilter($item);
}
}
}
}
示例13: testDatabaseLoaded
/**
* Tests that the database was properly loaded.
*/
public function testDatabaseLoaded()
{
foreach (['user', 'node', 'system', 'update_test_schema'] as $module) {
$this->assertEqual(drupal_get_installed_schema_version($module), 8000, SafeMarkup::format('Module @module schema is 8000', ['@module' => $module]));
}
// Ensure that all {router} entries can be unserialized. If they cannot be
// unserialized a notice will be thrown by PHP.
$result = \Drupal::database()->query("SELECT name, route from {router}")->fetchAllKeyed(0, 1);
// For the purpose of fetching the notices and displaying more helpful error
// messages, let's override the error handler temporarily.
set_error_handler(function ($severity, $message, $filename, $lineno) {
throw new \ErrorException($message, 0, $severity, $filename, $lineno);
});
foreach ($result as $route_name => $route) {
try {
unserialize($route);
} catch (\Exception $e) {
$this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name)));
}
}
restore_error_handler();
// Before accessing the site we need to run updates first or the site might
// be broken.
$this->runUpdates();
$this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
$this->drupalGet('<front>');
$this->assertText('Site-Install');
// Ensure that the database tasks have been run during set up. Neither MySQL
// nor SQLite make changes that are testable.
$database = $this->container->get('database');
if ($database->driver() == 'pgsql') {
$this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
$this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
}
}
示例14: bootstrap_drupal_configuration
function bootstrap_drupal_configuration()
{
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
// Unset drupal error handler and restore drush's one.
restore_error_handler();
parent::bootstrap_drupal_configuration();
}
示例15: tearDown
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
Configure::write('log', true);
if ($this->_restoreError) {
restore_error_handler();
}
}