-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Added configuration for additionnal request formats #9862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
10c2b06
[FrameworkBundle] Added configuration for additionnal request formats
gquemener 5781354
Fixed typo
gquemener 3ede4a2
[FramworkBundle] Fixed typos
gquemener e3e28fc
[FramworkBundle] Fixed CS
gquemener bbebbaf
[HttpKernel] Created the add request formats listener
gquemener 829c6c9
[FrameworkBundle] Directly injected formats into request listener
gquemener 399b7c0
[HttpKernel] Fixed code standard
gquemener 22b35b3
[FrameworkBundle] [HttpKernel] Renamed additional_formats into formats
gquemener e4ce0d6
[FrameworkBundle] Fixed conjugation
gquemener File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<parameters> | ||
<parameter key="request.add_request_formats_listener.class">Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener</parameter> | ||
</parameters> | ||
|
||
<services> | ||
<service id="request.add_request_formats_listener" class="%request.add_request_formats_listener.class%"> | ||
<tag name="kernel.event_subscriber" /> | ||
<argument/> | ||
</service> | ||
</services> | ||
</container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/request.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
$container->loadFromExtension('framework', array( | ||
'request' => array( | ||
'formats' => array(), | ||
), | ||
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/request.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
<framework:config> | ||
<framework:request /> | ||
</framework:config> | ||
</container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/request.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
framework: | ||
request: | ||
formats: ~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
|
||
/** | ||
* Adds configured formats to each request | ||
* | ||
* @author Gildas Quemener <gildas.quemener@gmail.com> | ||
*/ | ||
class AddRequestFormatsListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $formats; | ||
|
||
/** | ||
* @param array $formats | ||
*/ | ||
public function __construct(array $formats) | ||
{ | ||
$this->formats = $formats; | ||
} | ||
|
||
/** | ||
* Adds 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'); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\Tests\EventListener; | ||
|
||
use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
/** | ||
* Test AddRequestFormatsListener class | ||
* | ||
* @author Gildas Quemener <gildas.quemener@gmail.com> | ||
*/ | ||
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 testSetAdditionalFormats() | ||
{ | ||
$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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why checking here instead of at line 94?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No special reason, apart from the fact that it's kind of how it's done for other
register...
methods.