作者:alexbog
项目:symfon
public function testConfigure()
{
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
$userHandler = function () {
};
$listener = new DebugHandlersListener($userHandler, $logger);
$xHandler = new ExceptionHandler();
$eHandler = new ErrorHandler();
$eHandler->setExceptionHandler(array($xHandler, 'handle'));
$exception = null;
set_error_handler(array($eHandler, 'handleError'));
set_exception_handler(array($eHandler, 'handleException'));
try {
$listener->configure();
} catch (\Exception $exception) {
}
restore_exception_handler();
restore_error_handler();
if (null !== $exception) {
throw $exception;
}
$this->assertSame($userHandler, $xHandler->setHandler('var_dump'));
$loggers = $eHandler->setLoggers(array());
$this->assertArrayHasKey(E_DEPRECATED, $loggers);
$this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
}
作者:scrobo
项目:Lume
public function testConsoleEvent()
{
$dispatcher = new EventDispatcher();
$listener = new DebugHandlersListener(null);
$app = $this->getMock('Symfony\\Component\\Console\\Application');
$app->expects($this->once())->method('getHelperSet')->will($this->returnValue(new HelperSet()));
$command = new Command(__FUNCTION__);
$command->setApplication($app);
$event = new ConsoleEvent($command, new ArgvInput(), new ConsoleOutput());
$dispatcher->addSubscriber($listener);
$xListeners = array(KernelEvents::REQUEST => array(array($listener, 'configure')), ConsoleEvents::COMMAND => array(array($listener, 'configure')));
$this->assertSame($xListeners, $dispatcher->getListeners());
$exception = null;
$eHandler = new ErrorHandler();
set_error_handler(array($eHandler, 'handleError'));
set_exception_handler(array($eHandler, 'handleException'));
try {
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
} catch (\Exception $exception) {
}
restore_exception_handler();
restore_error_handler();
if (null !== $exception) {
throw $exception;
}
$xHandler = $eHandler->setExceptionHandler('var_dump');
$this->assertInstanceOf('Closure', $xHandler);
$app->expects($this->once())->method('renderException');
$xHandler(new \Exception());
}
作者:GeorgeBroadle
项目:caffeine-vendo
public function injectLogger()
{
if (null !== $this->logger) {
ErrorHandler::setLogger($this->logger, $this->channel);
$this->logger = null;
}
}
作者:anthrotec
项目:laravel_sampl
public function testStacking()
{
// the ContextErrorException must not be loaded to test the workaround
// for https://bugs.php.net/65322.
if (class_exists('Symfony\\Component\\Debug\\Exception\\ContextErrorException', false)) {
$this->markTestSkipped('The ContextErrorException class is already loaded.');
}
ErrorHandler::register();
try {
// Trigger autoloading + E_STRICT at compile time
// which in turn triggers $errorHandler->handle()
// that again triggers autoloading for ContextErrorException.
// Error stacking works around the bug above and everything is fine.
eval('
namespace ' . __NAMESPACE__ . ';
class ChildTestingStacking extends TestingStacking { function foo($bar) {} }
');
$this->fail('ContextErrorException expected');
} catch (\ErrorException $exception) {
// if an exception is thrown, the test passed
restore_error_handler();
restore_exception_handler();
$this->assertEquals(E_STRICT, $exception->getSeverity());
$this->assertStringStartsWith(__FILE__, $exception->getFile());
$this->assertRegexp('/^Runtime Notice: Declaration/', $exception->getMessage());
} catch (\Exception $e) {
restore_error_handler();
restore_exception_handler();
throw $e;
}
}
作者:nlegof
项目:Phraseane
/**
* Registers the autoloader and necessary components.
*
* @param string $name Name for this application.
* @param string|null $version Version number for this application.
* @param string|null $environment The environment.
*/
public function __construct($name, $version = null, $environment = self::ENV_PROD)
{
parent::__construct($environment);
$app = $this;
$this['session.test'] = true;
$this['console'] = $this->share(function () use($name, $version) {
return new Console\Application($name, $version);
});
$this['dispatcher'] = $this->share($this->extend('dispatcher', function (EventDispatcher $dispatcher, Application $app) {
$dispatcher->addListener('phraseanet.notification.sent', function () use($app) {
$app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']);
});
$dispatcher->addSubscriber(new BridgeSubscriber($app));
return $dispatcher;
}));
$this->register(new PluginServiceProvider());
$this->register(new WebsocketServerServiceProvider());
$this->register(new ComposerSetupServiceProvider());
$this->register(new CLIDriversServiceProvider());
$this->register(new LessBuilderServiceProvider());
$this->register(new SignalHandlerServiceProvider());
$this->register(new TaskManagerServiceProvider());
$this->register(new TranslationExtractorServiceProvider());
$this->register(new DoctrineMigrationServiceProvider());
$this->bindRoutes();
error_reporting(-1);
ErrorHandler::register();
PhraseaCLIExceptionHandler::register();
}
作者:phpmik
项目:MvErrorLogBundl
/**
* @return void
* @author Michaël VEROUX
*/
public function boot()
{
if ('prod' === $this->container->getParameter('kernel.environment')) {
$handler = ErrorHandler::register();
$handler->setExceptionHandler(array($this, 'handle'));
}
}
作者:romainneutro
项目:symfon
/**
* @expectedException \Symfony\Component\Debug\Exception\DummyException
*/
public function testStacking()
{
// the ContextErrorException must not be loaded to test the workaround
// for https://bugs.php.net/65322.
if (class_exists('Symfony\\Component\\Debug\\Exception\\ContextErrorException', false)) {
$this->markTestSkipped('The ContextErrorException class is already loaded.');
}
$exceptionHandler = $this->getMock('Symfony\\Component\\Debug\\ExceptionHandler', array('handle'));
set_exception_handler(array($exceptionHandler, 'handle'));
$that = $this;
$exceptionCheck = function ($exception) use($that) {
$that->assertInstanceOf('Symfony\\Component\\Debug\\Exception\\ContextErrorException', $exception);
$that->assertEquals(E_STRICT, $exception->getSeverity());
$that->assertStringStartsWith(__FILE__, $exception->getFile());
$that->assertRegexp('/^Runtime Notice: Declaration/', $exception->getMessage());
};
$exceptionHandler->expects($this->once())->method('handle')->will($this->returnCallback($exceptionCheck));
ErrorHandler::register();
try {
// Trigger autoloading + E_STRICT at compile time
// which in turn triggers $errorHandler->handle()
// that again triggers autoloading for ContextErrorException.
// Error stacking works around the bug above and everything is fine.
eval('
namespace ' . __NAMESPACE__ . ';
class ChildTestingStacking extends TestingStacking { function foo($bar) {} }
');
} catch (\Exception $e) {
restore_error_handler();
restore_exception_handler();
throw $e;
}
restore_error_handler();
restore_exception_handler();
}
作者:cmsile
项目:cmsile
public function bootstrap()
{
$app = $this;
$app['dir.base'] = __DIR__ . "/../../../../";
$app->register(new ConfigServiceProvider());
$app['debug'] = $app['config']['debug'];
ErrorHandler::register();
ExceptionHandler::register($app['debug']);
$app->register(new HttpFragmentServiceProvider());
$app->register(new ServiceControllerServiceProvider());
$app->register(new ORMServiceProvider());
$app->register(new SessionServiceProvider());
$app->register(new SecurityServiceProvider());
$app['security.encoder.digest'] = function ($app) {
// uses the password-compat encryption
return new BCryptPasswordEncoder(10);
};
$app->register(new ManagerRegistryServiceProvider());
$app['security.firewalls'] = array('default' => array('pattern' => '/', 'form' => array('login_path' => '/login', 'check_path' => '/login_check'), 'logout' => array('logout_path' => '/logout', 'invalidate_session' => true), 'users' => function () use($app) {
return new EntityUserProvider($app['manager_registry'], User::class, 'username');
}, 'anonymous' => true));
$app['security.access_rules'] = [['^/admin', 'ROLE_ADMIN']];
$app->register(new TranslationServiceProvider(), array('locale_fallbacks' => array('en'), 'locale' => 'en'));
$app->register(new ValidatorServiceProvider());
$app->register(new FormServiceProvider());
$app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../resources/views', 'twig.form.templates' => ['bootstrap_3_layout.html.twig'], 'twig.strict_variables' => false]);
$app->extend('twig', function (\Twig_Environment $twig) {
$twig->addTest(new \Twig_SimpleTest('callable', function ($variable) {
return is_callable($variable);
}));
$twig->addFunction(new \Twig_SimpleFunction('is_callable', function ($variable) {
return is_callable($variable);
}));
$twig->addFunction(new \Twig_SimpleFunction('call_user_func', function ($callable, $params = null) {
return call_user_func($callable, $params);
}));
$twig->getExtension('core')->setDateFormat('Y/m/d', '%d days');
return $twig;
});
$app->extend('form.types', function ($types) use($app) {
$types[] = new EntityType($app['manager_registry']);
$types[] = new TemplateChoiceType($app['theme']);
$types[] = new PageType($app['theme']);
return $types;
});
$app->register(new SerializerServiceProvider());
$app->register(new WebProfilerServiceProvider(), ['profiler.cache_dir' => './../storage/framework/cache/profiler', 'web_profiler.debug_toolbar.enable' => $app['debug'], 'profiler.mount_prefix' => '/admin/_profiler']);
$app['finder'] = function () {
return new Finder();
};
$app['filesystem'] = function () {
return new Filesystem();
};
$app->register(new ConverterServiceProvider());
$app->register(new ThemeServiceProvider());
$app['twig.loader.filesystem']->addPath($app['dir.theme'], 'theme');
$app->register(new CMSServiceProvider());
$app->setRoutes();
}
作者:jacobjj
项目:PageKit-framewor
public function register(Application $app)
{
$debug = isset($app['config']) ? $app['config']['app.debug'] : true;
$handler = ExceptionHandler::register($debug);
ErrorHandler::register(E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
if ($cli = $app->runningInConsole() or $debug) {
ini_set('display_errors', 1);
}
$app['exception'] = $handler;
}
作者:schnell
项目:volkszaehler.or
/**
* Constructor
*/
public function __construct()
{
// handle errors as exceptions
ErrorHandler::register();
// views
if (class_exists('\\JpGraph\\JpGraph')) {
foreach (array('png', 'jpeg', 'jpg', 'gif') as $format) {
self::$viewMapping[$format] = 'Volkszaehler\\View\\JpGraph';
}
}
}
作者:izziaraffael
项目:webcompose
public function register(Application $app)
{
ErrorHandler::register();
ExceptionHandler::register($app['debug']);
$app->error(function (\Exception $exception, $code) use($app) {
if (!$app['debug'] || $code === 404) {
// 404.html, or 40x.html, or 4xx.html, or error.html
$templates = array('errors/' . $code . '.html.twig', 'errors/' . substr($code, 0, 2) . 'x.html.twig', 'errors/' . substr($code, 0, 1) . 'xx.html.twig', 'errors/' . 'default.html.twig');
return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
}
});
}
作者:nawras
项目:tvguid
public function __construct()
{
parent::__construct();
// Convert errors to exceptions
ErrorHandler::register();
ExceptionHandler::register();
$this['cache.directory'] = __DIR__ . '/../../../app/cache';
$this['vendor.directory'] = __DIR__ . '/../../../vendor';
$this->registerControllers();
$this->registerServiceProviders();
$this->registerInternalServices();
}
作者:lmaslowsk
项目:phpbenc
public static function run()
{
// Converts warnings to exceptions
ErrorHandler::register();
$config = self::loadConfig();
$container = new Container($config['extensions']);
unset($config['extensions']);
$container->configure();
$container->mergeParameters($config);
$container->build();
$container->get('console.application')->run();
}
作者:jdesrosier
项目:resourcefu
public function __construct($config = array())
{
parent::__construct($config);
ErrorHandler::register();
// JSON/REST application
$this->register(new ContentNegotiationServiceProvider(), array("conneg.responseFormats" => array("json"), "conneg.requestFormats" => array("json"), "conneg.defaultFormat" => "json"));
$this->register(new CorsServiceProvider());
// JSON Schema application
$this->register(new JsonSchemaServiceProvider());
// Error Handling
$this->error(new JsonErrorHandler($this));
}
作者:kebool
项目:syru
public static function enable($environment = 'dev')
{
if (static::$enabled) {
return;
}
static::$enabled = true;
error_reporting(-1);
// Beware, ExceptionHandler::register and ErrorHandler::register must be called in this order
// to fatal errors handling work
ExceptionHandler::register(true, $environment);
ErrorHandler::register();
DebugClassLoader::enable();
}
作者:Dren-
项目:mobi
public function boot()
{
ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
Request::setTrustedProxies($trustedProxies);
}
if ($this->container->getParameter('kernel.http_method_override')) {
Request::enableHttpMethodParameterOverride();
}
if ($trustedHosts = $this->container->getParameter('kernel.trusted_hosts')) {
Request::setTrustedHosts($trustedHosts);
}
}
作者:stoned
项目:pff
/**
* Sets error reporting
*/
public function setErrorReporting()
{
if (true === $this->_config->getConfigData('development_environment')) {
error_reporting(E_ALL);
ini_set('display_errors', 'On');
ErrorHandler::register();
} else {
error_reporting(E_ALL);
ini_set('display_errors', 'Off');
ini_set('log_errors', 'On');
ini_set('error_log', ROOT . DS . 'tmp' . DS . 'logs' . DS . 'error.log');
}
}
作者:billwaddyj
项目:Favorite-This-Dem
/**
* Enables the debug tools.
*
* This method registers an error handler and an exception handler.
*
* If the Symfony ClassLoader component is available, a special
* class loader is also registered.
*
* @param integer $errorReportingLevel The level of error reporting you want
* @param Boolean $displayErrors Whether to display errors (for development) or just log them (for production)
*/
public static function enable($errorReportingLevel = null, $displayErrors = true)
{
if (static::$enabled) {
return;
}
static::$enabled = true;
error_reporting(-1);
ErrorHandler::register($errorReportingLevel, $displayErrors);
if ('cli' !== php_sapi_name()) {
ExceptionHandler::register();
// CLI - display errors only if they're not already logged to STDERR
} elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
ini_set('display_errors', 1);
}
DebugClassLoader::enable();
}
作者:eddmas
项目:poweror
/**
* Loads third party libraries.
*
* @since 1.1.0
*
* @author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
*/
public static function loadThirdParty()
{
$ds = DIRECTORY_SEPARATOR;
$vendorDir = sprintf('%1$s%2$svendor%2$s', HOMEPATH, $ds);
if (file_exists($vendorDir . 'doctrine')) {
$path = '%1$sdoctrine%2$scommon%2$slib%2$sDoctrine%2$sCommon%2$sClassLoader.php';
require sprintf($path, $vendorDir, $ds);
$commonLoader = new \Doctrine\Common\ClassLoader('Doctrine', $vendorDir . 'doctrine' . $ds . 'common' . $ds . 'lib');
$commonLoader->register();
$dbalLoader = new \Doctrine\Common\ClassLoader('Doctrine', $vendorDir . 'doctrine' . $ds . 'dbal' . $ds . 'lib');
$dbalLoader->register();
}
if (file_exists($vendorDir . $ds . 'symfony' . $ds . 'debug')) {
ErrorHandler::register();
}
}
作者:ioano
项目:symfoxi
/**
* Sets default exception handler.
*
* If shop is in productive mode stick to default OXID exception handler
* Else register Symfony Debug component's Exception and Error handlers
*
* Non-productive eShop mode is intended for eShop installation, configuration, template customization and module debugging phase.
* As soon as productive mode is turned ON, the cache handling and the error reporting behavior is optimized for the live shop.
*/
protected function _setDefaultExceptionHandler()
{
/**
* @todo: consider also getEnvironment() function to detect environment
*/
if (oxRegistry::getConfig()->isProductiveMode()) {
parent::_setDefaultExceptionHandler();
return;
}
/**
* Debug::enable() also registers a DebugClassLoader which throw an error because oxid does not care about case when referring to objects
* symfony is key sensitive: oxarticlelist != oxArticleList
*/
//Debug\Debug::enable();
ini_set('display_errors', 0);
Debug\ExceptionHandler::register();
Debug\ErrorHandler::register()->throwAt(0, true);
}