diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index ce404abf80..4c304d44ba 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -117,10 +117,12 @@ FrameworkBundle * The `framework.serializer.cache` option and the services `serializer.mapping.cache.apc` and `serializer.mapping.cache.doctrine.apc` have been removed. APCu should now be automatically used when available. - + * The `Controller::getUser()` method has been removed in favor of the ability to typehint the security user object in the action. + * The default value of the `framework.php_errors.log` configuration key is set to true. + HttpKernel ---------- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index c73c9e26e8..b459217ce6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -116,6 +116,7 @@ class Configuration implements ConfigurationInterface $this->addPropertyAccessSection($rootNode); $this->addPropertyInfoSection($rootNode); $this->addCacheSection($rootNode); + $this->addPhpErrorsSection($rootNode); return $treeBuilder; } @@ -692,4 +693,28 @@ class Configuration implements ConfigurationInterface ->end() ; } + + private function addPhpErrorsSection(ArrayNodeDefinition $rootNode) + { + $rootNode + ->children() + ->arrayNode('php_errors') + ->info('PHP errors handling configuration') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('log') + ->info('Use the app logger instead of the PHP logger for logging PHP errors.') + ->defaultValue(false) + ->treatNullLike(false) + ->end() + ->booleanNode('throw') + ->info('Throw PHP errors as \ErrorException instances.') + ->defaultValue($this->debug) + ->treatNullLike($this->debug) + ->end() + ->end() + ->end() + ->end() + ; + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 806a06197c..be514be082 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -131,6 +131,7 @@ class FrameworkExtension extends Extension $this->registerProfilerConfiguration($config['profiler'], $container, $loader); $this->registerCacheConfiguration($config['cache'], $container); $this->registerWorkflowConfiguration($config['workflows'], $container, $loader); + $this->registerDebugConfiguration($config['php_errors'], $container, $loader); if ($this->isConfigEnabled($container, $config['router'])) { $this->registerRouterConfiguration($config['router'], $container, $loader); @@ -147,27 +148,6 @@ class FrameworkExtension extends Extension $this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader); } - $loader->load('debug_prod.xml'); - $definition = $container->findDefinition('debug.debug_handlers_listener'); - - if ($container->hasParameter('templating.helper.code.file_link_format')) { - $definition->replaceArgument(5, '%templating.helper.code.file_link_format%'); - } - - if ($container->getParameter('kernel.debug')) { - $definition->replaceArgument(2, E_ALL & ~(E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR | E_RECOVERABLE_ERROR)); - - $loader->load('debug.xml'); - - // replace the regular event_dispatcher service with the debug one - $definition = $container->findDefinition('event_dispatcher'); - $definition->setPublic(false); - $container->setDefinition('debug.event_dispatcher.parent', $definition); - $container->setAlias('event_dispatcher', 'debug.event_dispatcher'); - } else { - $definition->replaceArgument(1, null); - } - $this->addAnnotatedClassesToCompile(array( '**Bundle\\Controller\\', '**Bundle\\Entity\\', @@ -417,6 +397,48 @@ class FrameworkExtension extends Extension } } + /** + * Loads the debug configuration. + * + * @param array $config A php errors configuration array + * @param ContainerBuilder $container A ContainerBuilder instance + * @param XmlFileLoader $loader An XmlFileLoader instance + */ + private function registerDebugConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) + { + $loader->load('debug_prod.xml'); + + $debug = $container->getParameter('kernel.debug'); + + if ($debug) { + $loader->load('debug.xml'); + + // replace the regular event_dispatcher service with the debug one + $definition = $container->findDefinition('event_dispatcher'); + $definition->setPublic(false); + $container->setDefinition('debug.event_dispatcher.parent', $definition); + $container->setAlias('event_dispatcher', 'debug.event_dispatcher'); + } + + $definition = $container->findDefinition('debug.debug_handlers_listener'); + + if (!$config['log']) { + $definition->replaceArgument(1, null); + } + + if (!$config['throw']) { + $container->setParameter('debug.error_handler.throw_at', 0); + } + + $definition->replaceArgument(4, $debug); + + if ($container->hasParameter('templating.helper.code.file_link_format')) { + $definition->replaceArgument(5, '%templating.helper.code.file_link_format%'); + } + + $definition->replaceArgument(6, $debug); + } + /** * Loads the router configuration. * diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml index b6e7c0599b..073851b038 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml @@ -6,7 +6,6 @@ %kernel.cache_dir%/%kernel.container_class%.xml - -1 diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml index 3ef3ec90d0..d4eb5b1762 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - 0 + -1 @@ -14,10 +14,11 @@ null - null - null + -1 + %debug.error_handler.throw_at% true null + true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index bcea367682..1af6aacf2c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -274,6 +274,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'default_redis_provider' => 'redis://localhost', ), 'workflows' => array(), + 'php_errors' => array( + 'log' => false, + 'throw' => true, + ), ); } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig index bf76eb0e1a..7ad2d3a273 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig @@ -6,7 +6,7 @@ {% if collector.counterrors or collector.countdeprecations or collector.countscreams %} {% set icon %} {% set status_color = collector.counterrors ? 'red' : collector.countdeprecations ? 'yellow' : '' %} - {% set error_count = collector.counterrors + collector.countdeprecations + collector.countscreams %} + {% set error_count = collector.counterrors + collector.countdeprecations %} {{ include('@WebProfiler/Icon/logger.svg') }} {{ error_count }} {% endset %} @@ -55,7 +55,7 @@ {# sort collected logs in groups #} {% set deprecation_logs, debug_logs, info_and_error_logs, silenced_logs = [], [], [], [] %} {% for log in collector.logs %} - {% if log.context.level is defined and log.context.type is defined and log.context.type in [constant('E_DEPRECATED'), constant('E_USER_DEPRECATED')] %} + {% if log.context.errorCount is defined and log.context.type is defined and log.context.type in ['E_DEPRECATED', 'E_USER_DEPRECATED'] %} {% set deprecation_logs = deprecation_logs|merge([log]) %} {% elseif log.context.scream is defined and log.context.scream == true %} {% set silenced_logs = silenced_logs|merge([log]) %} @@ -170,21 +170,22 @@ {% macro render_log_message(category, log_index, log, is_deprecation = false) %} {{ log.message }} + {% if log.context.errorCount is defined and log.context.errorCount > 1 %} + ({{ log.context.errorCount }} times) + {% endif %} + {% if is_deprecation %} - {% set stack = log.context.stack|default([]) %} - {% set stack_id = 'sf-call-stack-' ~ category ~ '-' ~ log_index %} + {% set trace = log.context.trace|default([]) %} + {% set trace_id = 'sf-call-trace-' ~ category ~ '-' ~ log_index %} - {% if log.context.errorCount is defined %} - ({{ log.context.errorCount }} times) + + {% if trace %} + {% endif %} - {% if stack %} - - {% endif %} - - {% for index, call in stack if index > 1 %} + {% for index, call in trace if index > 1 %} {% if index == 2 %} -