From 10c2b06b37c10ced63af432d1af324af823fc226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Wed, 25 Dec 2013 22:24:54 +0100 Subject: [PATCH 1/9] [FrameworkBundle] Added configuration for additionnal request formats --- .../DependencyInjection/Configuration.php | 30 +++++++ .../FrameworkExtension.php | 19 +++++ .../AddRequestFormatsListener.php | 59 +++++++++++++ .../Resources/config/request.xml | 17 ++++ .../Resources/config/schema/symfony-1.0.xsd | 14 +++ .../DependencyInjection/Fixtures/php/full.php | 11 ++- .../Fixtures/php/request.php | 7 ++ .../DependencyInjection/Fixtures/xml/full.xml | 9 ++ .../Fixtures/xml/request.xml | 11 +++ .../DependencyInjection/Fixtures/yml/full.yml | 4 + .../Fixtures/yml/request.yml | 3 + .../FrameworkExtensionTest.php | 15 ++++ .../AddRequestFormatsListenerTest.php | 85 +++++++++++++++++++ 13 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/request.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 0c1d1578c6f0..e7afcbf37b7b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -85,6 +85,7 @@ public function getConfigTreeBuilder() $this->addProfilerSection($rootNode); $this->addRouterSection($rootNode); $this->addSessionSection($rootNode); + $this->addRequestSection($rootNode); $this->addTemplatingSection($rootNode); $this->addTranslatorSection($rootNode); $this->addValidationSection($rootNode); @@ -256,6 +257,35 @@ private function addSessionSection(ArrayNodeDefinition $rootNode) ; } + private function addRequestSection(ArrayNodeDefinition $rootNode) + { + $rootNode + ->children() + ->arrayNode('request') + ->info('request configuration') + ->canBeUnset() + ->fixXmlConfig('additional_format') + ->children() + ->arrayNode('additional_formats') + ->useAttributeAsKey('name') + ->prototype('array') + ->beforeNormalization() + ->ifTrue(function ($v) { return is_array($v) && isset($v['mime_type']); }) + ->then(function ($v) { return $v['mime_type']; }) + ->end() + ->beforeNormalization() + ->ifTrue(function ($v) { return !is_array($v); }) + ->then(function ($v) { return array($v); }) + ->end() + ->prototype('scalar')->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ; + } + private function addTemplatingSection(ArrayNodeDefinition $rootNode) { $organizeUrls = function ($urls) { diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 5dc5c05513f0..33fc94411c79 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -91,6 +91,10 @@ public function load(array $configs, ContainerBuilder $container) $this->registerSessionConfiguration($config['session'], $container, $loader); } + if (isset($config['request'])) { + $this->registerRequestConfiguration($config['request'], $container, $loader); + } + $loader->load('security.xml'); if ($this->isConfigEnabled($container, $config['form'])) { @@ -382,6 +386,21 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c $container->setParameter('session.metadata.update_threshold', $config['metadata_update_threshold']); } + /** + * Loads the request configuration. + * + * @param array $config A session configuration array + * @param ContainerBuilder $container A ContainerBuilder instance + * @param XmlFileLoader $loader An XmlFileLoader instance + */ + private function registerRequestConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) + { + if ($config['additional_formats']) { + $container->setParameter('request.additional_formats', $config['additional_formats']); + $loader->load('request.xml'); + } + } + /** * Loads the templating configuration. * diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php new file mode 100644 index 000000000000..6ba098e0183d --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\EventListener; + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; + +/** + * Set additional formats into the request + * + * @author Gildas Quemener + */ +class AddRequestFormatsListener implements EventSubscriberInterface +{ + /** + * @var array + */ + protected $formats; + + /** + * @param array $formats + */ + public function __construct(array $formats) + { + $this->formats = $formats; + } + + /** + * Set additionnal request formats + * + * @param GetResponseEvent $event + */ + public function onKernelRequest(GetResponseEvent $event) + { + foreach ($this->formats as $format => $mimeTypes) { + $event->getRequest()->setFormat($format, $mimeTypes); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array( + KernelEvents::REQUEST => 'onKernelRequest', + ); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml new file mode 100644 index 000000000000..0170c95c4312 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml @@ -0,0 +1,17 @@ + + + + + + Symfony\Bundle\FrameworkBundle\EventListener\AddRequestFormatsListener + + + + + + %request.additional_formats% + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 92c8952e48be..435718706aa5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -16,6 +16,7 @@ + @@ -101,6 +102,19 @@ + + + + + + + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index c4eff9349228..bfc00f13d6d8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -70,5 +70,14 @@ 'debug' => true, 'file_cache_dir' => '%kernel.cache_dir%/annotations', ), - 'ide' => 'file%%link%%format' + 'ide' => 'file%%link%%format', + 'request' => array( + 'additional_formats' => array( + 'csv' => array( + 'text/csv', + 'text/plain', + ), + 'pdf' => 'application/pdf' + ) + ) )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php new file mode 100644 index 000000000000..06624e29b0f1 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php @@ -0,0 +1,7 @@ +loadFromExtension('framework', array( + 'request' => array( + 'additional_formats' => array(), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 8fd3e9b6528a..24e86aa6fddf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -13,6 +13,15 @@ + + + text/csv + text/plain + + + application/pdf + + loader.foo loader.bar diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/request.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/request.xml new file mode 100644 index 000000000000..320d1b187525 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/request.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index d013063916c3..eca9a788b944 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -55,3 +55,7 @@ framework: debug: true file_cache_dir: %kernel.cache_dir%/annotations ide: file%%link%%format + request: + additional_formats: + csv: ['text/csv', 'text/plain'] + pdf: 'application/pdf' diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml new file mode 100644 index 000000000000..50a8e227cefd --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml @@ -0,0 +1,3 @@ +framework: + request: + additional_formats: ~ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 94ba71d44857..160bc3c4750e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -145,6 +145,21 @@ public function testNullSessionHandler() $this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0)); } + public function testRequest() + { + $container = $this->createContainerFromFile('full'); + + $this->assertTrue($container->hasDefinition('request.add_request_formats_listener'), '->registerRequestConfiguration() loads request.xml'); + $this->assertEquals(array('csv' => array('text/csv', 'text/plain'), 'pdf' => array('application/pdf')), $container->getParameter('request.additional_formats')); + } + + public function testEmptyAdditionlRequestFormats() + { + $container = $this->createContainerFromFile('request'); + + $this->assertFalse($container->hasDefinition('request.add_request_formats_listener'), '->registerRequestConfiguration() does not load request.xml when no additional request formats are configured'); + } + public function testTemplating() { $container = $this->createContainerFromFile('full'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php new file mode 100644 index 000000000000..7357c82eed2a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -0,0 +1,85 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\EventListener; + +use Symfony\Bundle\FrameworkBundle\EventListener\AddRequestFormatsListener; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\KernelEvents; + +/** + * Test AddRequestFormatsListener class + * + * @author Gildas Quemener + */ +class AddRequestFormatsListenerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var AddRequestFormatsListener + */ + private $listener; + + protected function setUp() + { + $this->listener = new AddRequestFormatsListener(array('csv' => array('text/csv', 'text/plain'))); + } + + protected function tearDown() + { + $this->listener = null; + } + + public function testIsAnEventSubscriber() + { + $this->assertInstanceOf('Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); + } + + public function testRegisteredEvent() + { + $this->assertEquals( + array( + KernelEvents::REQUEST => 'onKernelRequest', + ), + AddRequestFormatsListener::getSubscribedEvents() + ); + } + + public function testSetAdditionnalFormats() + { + $request = $this->getRequestMock(); + $event = $this->getGetResponseEventMock($request); + + $request->expects($this->once()) + ->method('setFormat') + ->with('csv', array('text/csv', 'text/plain')); + + $this->listener->onKernelRequest($event); + } + + protected function getRequestMock() + { + return $this->getMock('Symfony\Component\HttpFoundation\Request'); + } + + protected function getGetResponseEventMock(Request $request) + { + $event = $this + ->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + ->disableOriginalConstructor() + ->getMock(); + + $event->expects($this->any()) + ->method('getRequest') + ->will($this->returnValue($request)); + + return $event; + } +} From 578135450a84f0b486d753b9099b740d0fe817de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Thu, 26 Dec 2013 18:43:53 +0100 Subject: [PATCH 2/9] Fixed typo --- .../FrameworkBundle/EventListener/AddRequestFormatsListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php index 6ba098e0183d..97caf767dc68 100644 --- a/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php @@ -36,7 +36,7 @@ public function __construct(array $formats) } /** - * Set additionnal request formats + * Set additional request formats * * @param GetResponseEvent $event */ From 3ede4a22e6e6af72212db359ab4686f89ea7cca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Fri, 27 Dec 2013 14:23:27 +0100 Subject: [PATCH 3/9] [FramworkBundle] Fixed typos --- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 2 +- .../Tests/EventListener/AddRequestFormatsListenerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 160bc3c4750e..4155bc5c2456 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -153,7 +153,7 @@ public function testRequest() $this->assertEquals(array('csv' => array('text/csv', 'text/plain'), 'pdf' => array('application/pdf')), $container->getParameter('request.additional_formats')); } - public function testEmptyAdditionlRequestFormats() + public function testEmptyAdditionalRequestFormats() { $container = $this->createContainerFromFile('request'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php index 7357c82eed2a..b5a98c0dac3f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -52,7 +52,7 @@ public function testRegisteredEvent() ); } - public function testSetAdditionnalFormats() + public function testSetAdditionalFormats() { $request = $this->getRequestMock(); $event = $this->getGetResponseEventMock($request); From e3e28fc44e2e327f949df1ef681ffb15d2cd4f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Fri, 27 Dec 2013 14:23:44 +0100 Subject: [PATCH 4/9] [FramworkBundle] Fixed CS --- .../Tests/EventListener/AddRequestFormatsListenerTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php index b5a98c0dac3f..68723444289c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -45,9 +45,7 @@ public function testIsAnEventSubscriber() public function testRegisteredEvent() { $this->assertEquals( - array( - KernelEvents::REQUEST => 'onKernelRequest', - ), + array(KernelEvents::REQUEST => 'onKernelRequest'), AddRequestFormatsListener::getSubscribedEvents() ); } From bbebbaf145ed7d81440dad4ccac93b020a5112b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Tue, 31 Dec 2013 10:49:11 +0100 Subject: [PATCH 5/9] [HttpKernel] Created the add request formats listener --- .../Bundle/FrameworkBundle/Resources/config/request.xml | 2 +- .../HttpKernel}/EventListener/AddRequestFormatsListener.php | 2 +- .../Tests/EventListener/AddRequestFormatsListenerTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/Symfony/{Bundle/FrameworkBundle => Component/HttpKernel}/EventListener/AddRequestFormatsListener.php (95%) rename src/Symfony/{Bundle/FrameworkBundle => Component/HttpKernel}/Tests/EventListener/AddRequestFormatsListenerTest.php (93%) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml index 0170c95c4312..fcffc9840499 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Symfony\Bundle\FrameworkBundle\EventListener\AddRequestFormatsListener + Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php similarity index 95% rename from src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php rename to src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php index 97caf767dc68..7adbfd443df6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/EventListener/AddRequestFormatsListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Bundle\FrameworkBundle\EventListener; +namespace Symfony\Component\HttpKernel\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php similarity index 93% rename from src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php rename to src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php index 68723444289c..26bdf7067374 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Bundle\FrameworkBundle\Tests\EventListener; +namespace Symfony\Component\HttpKernel\Tests\EventListener; -use Symfony\Bundle\FrameworkBundle\EventListener\AddRequestFormatsListener; +use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\KernelEvents; From 829c6c95154ae4689c2083966e21005f84ac4ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Tue, 31 Dec 2013 11:04:44 +0100 Subject: [PATCH 6/9] [FrameworkBundle] Directly injected formats into request listener --- .../DependencyInjection/FrameworkExtension.php | 5 ++++- .../Bundle/FrameworkBundle/Resources/config/request.xml | 2 +- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 33fc94411c79..567311011586 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -396,8 +396,11 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c private function registerRequestConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) { if ($config['additional_formats']) { - $container->setParameter('request.additional_formats', $config['additional_formats']); $loader->load('request.xml'); + $container + ->getDefinition('request.add_request_formats_listener') + ->replaceArgument(0, $config['additional_formats']) + ; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml index fcffc9840499..cc836c35e3b0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml @@ -11,7 +11,7 @@ - %request.additional_formats% + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 4155bc5c2456..d1a29c382c59 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -150,7 +150,8 @@ public function testRequest() $container = $this->createContainerFromFile('full'); $this->assertTrue($container->hasDefinition('request.add_request_formats_listener'), '->registerRequestConfiguration() loads request.xml'); - $this->assertEquals(array('csv' => array('text/csv', 'text/plain'), 'pdf' => array('application/pdf')), $container->getParameter('request.additional_formats')); + $listenerDef = $container->getDefinition('request.add_request_formats_listener'); + $this->assertEquals(array('csv' => array('text/csv', 'text/plain'), 'pdf' => array('application/pdf')), $listenerDef->getArgument(0)); } public function testEmptyAdditionalRequestFormats() From 399b7c0740f4d61abcaffe806ba717819c35b0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Tue, 31 Dec 2013 11:10:05 +0100 Subject: [PATCH 7/9] [HttpKernel] Fixed code standard --- .../HttpKernel/EventListener/AddRequestFormatsListener.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php index 7adbfd443df6..de272434a1f8 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php @@ -36,7 +36,7 @@ public function __construct(array $formats) } /** - * Set additional request formats + * Set additional requests formats * * @param GetResponseEvent $event */ @@ -52,8 +52,6 @@ public function onKernelRequest(GetResponseEvent $event) */ public static function getSubscribedEvents() { - return array( - KernelEvents::REQUEST => 'onKernelRequest', - ); + return array(KernelEvents::REQUEST => 'onKernelRequest'); } } From 22b35b32fb95204a68b1ff031fd748454b37573b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Fri, 3 Jan 2014 15:10:54 +0100 Subject: [PATCH 8/9] [FrameworkBundle] [HttpKernel] Renamed additional_formats into formats --- .../FrameworkBundle/DependencyInjection/Configuration.php | 4 ++-- .../DependencyInjection/FrameworkExtension.php | 4 ++-- .../Resources/config/schema/symfony-1.0.xsd | 4 ++-- .../Tests/DependencyInjection/Fixtures/php/full.php | 2 +- .../Tests/DependencyInjection/Fixtures/php/request.php | 2 +- .../Tests/DependencyInjection/Fixtures/xml/full.xml | 8 ++++---- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/request.yml | 2 +- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 4 ++-- .../EventListener/AddRequestFormatsListener.php | 4 ++-- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index e7afcbf37b7b..b79bea6ad0ad 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -264,9 +264,9 @@ private function addRequestSection(ArrayNodeDefinition $rootNode) ->arrayNode('request') ->info('request configuration') ->canBeUnset() - ->fixXmlConfig('additional_format') + ->fixXmlConfig('format') ->children() - ->arrayNode('additional_formats') + ->arrayNode('formats') ->useAttributeAsKey('name') ->prototype('array') ->beforeNormalization() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 567311011586..3221e74d92d1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -395,11 +395,11 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c */ private function registerRequestConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) { - if ($config['additional_formats']) { + if ($config['formats']) { $loader->load('request.xml'); $container ->getDefinition('request.add_request_formats_listener') - ->replaceArgument(0, $config['additional_formats']) + ->replaceArgument(0, $config['formats']) ; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 435718706aa5..fcc9e254589d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -104,11 +104,11 @@ - + - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index bfc00f13d6d8..8bdb59f33d73 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -72,7 +72,7 @@ ), 'ide' => 'file%%link%%format', 'request' => array( - 'additional_formats' => array( + 'formats' => array( 'csv' => array( 'text/csv', 'text/plain', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php index 06624e29b0f1..1e7cb2921c4c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php @@ -2,6 +2,6 @@ $container->loadFromExtension('framework', array( 'request' => array( - 'additional_formats' => array(), + 'formats' => array(), ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 24e86aa6fddf..da3a5355467b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -14,13 +14,13 @@ - + text/csv text/plain - - + + application/pdf - + loader.foo diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index eca9a788b944..2e6f4c5388d1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -56,6 +56,6 @@ framework: file_cache_dir: %kernel.cache_dir%/annotations ide: file%%link%%format request: - additional_formats: + formats: csv: ['text/csv', 'text/plain'] pdf: 'application/pdf' diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml index 50a8e227cefd..9beae1dc5975 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml @@ -1,3 +1,3 @@ framework: request: - additional_formats: ~ + formats: ~ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index d1a29c382c59..d36203e3682d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -154,11 +154,11 @@ public function testRequest() $this->assertEquals(array('csv' => array('text/csv', 'text/plain'), 'pdf' => array('application/pdf')), $listenerDef->getArgument(0)); } - public function testEmptyAdditionalRequestFormats() + public function testEmptyRequestFormats() { $container = $this->createContainerFromFile('request'); - $this->assertFalse($container->hasDefinition('request.add_request_formats_listener'), '->registerRequestConfiguration() does not load request.xml when no additional request formats are configured'); + $this->assertFalse($container->hasDefinition('request.add_request_formats_listener'), '->registerRequestConfiguration() does not load request.xml when no request formats are defined'); } public function testTemplating() diff --git a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php index de272434a1f8..26f8069374b7 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent; /** - * Set additional formats into the request + * Add request formats listener * * @author Gildas Quemener */ @@ -36,7 +36,7 @@ public function __construct(array $formats) } /** - * Set additional requests formats + * Add request formats * * @param GetResponseEvent $event */ From e4ce0d6bcecf535c33dc8aa102be99dda033ee62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Thu, 9 Jan 2014 11:08:15 +0100 Subject: [PATCH 9/9] [FrameworkBundle] Fixed conjugation --- .../HttpKernel/EventListener/AddRequestFormatsListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php index 26f8069374b7..c37a537009e9 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent; /** - * Add request formats listener + * Adds configured formats to each request * * @author Gildas Quemener */ @@ -36,7 +36,7 @@ public function __construct(array $formats) } /** - * Add request formats + * Adds request formats * * @param GetResponseEvent $event */ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy