1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/14124] Automatically translate exceptions in CLI

PHPBB3-14124
This commit is contained in:
Tristan Darricau
2015-08-24 12:04:22 +02:00
parent f6a4843c6d
commit 17e7a89a60
9 changed files with 109 additions and 0 deletions

View File

@@ -13,6 +13,7 @@
namespace phpbb\console;
use phpbb\exception\exception_interface;
use Symfony\Component\Console\Shell;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

View File

@@ -0,0 +1,74 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\console;
use phpbb\exception\exception_interface;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class exception_subscriber implements EventSubscriberInterface
{
/**
* @var \phpbb\language\language
*/
protected $language;
/**
* Construct method
*
* @param \phpbb\language\language $language Language object
* @param bool $debug Debug mode
*/
public function __construct(\phpbb\language\language $language, $debug = false)
{
$this->language = $language;
$this->debug = $debug;
}
/**
* This listener is run when the ConsoleEvents::EXCEPTION event is triggered.
* It translate the exception message. If din debug mode the original exception is embedded.
*
* @param ConsoleExceptionEvent $event
*/
public function on_exception(ConsoleExceptionEvent $event)
{
$original_exception = $event->getException();
if ($original_exception instanceof exception_interface)
{
$parameters = array_merge(array($original_exception->getMessage()), $original_exception->get_parameters());
$message = call_user_func_array(array($this->language, 'lang'), $parameters);
if ($this->debug)
{
$exception = new \RuntimeException($message , $original_exception->getCode(), $original_exception);
}
else
{
$exception = new \RuntimeException($message , $original_exception->getCode());
}
$event->setException($exception);
}
}
static public function getSubscribedEvents()
{
return array(
ConsoleEvents::EXCEPTION => 'on_exception',
);
}
}

View File

@@ -31,6 +31,12 @@ class container_configuration implements ConfigurationInterface
$rootNode
->children()
->booleanNode('require_dev_dependencies')->defaultValue(false)->end()
->arrayNode('debug')
->addDefaultsIfNotSet()
->children()
->booleanNode('exceptions')->defaultValue(false)->end()
->end()
->end()
->arrayNode('twig')
->addDefaultsIfNotSet()
->children()

View File

@@ -80,6 +80,7 @@ class core extends Extension
{
$twig_environment_options['auto_reload'] = true;
}
// Replace the 8th argument, the options passed to the environment
$definition->replaceArgument(7, $twig_environment_options);
@@ -88,6 +89,12 @@ class core extends Extension
$definition = $container->getDefinition('template.twig.extensions.debug');
$definition->addTag('twig.extension');
}
// Set the debug options
foreach ($config['debug'] as $name => $value)
{
$container->setParameter('debug.' . $name, $value);
}
}
/**