From 0db32e35b8b1b7ee9852a5bd93a3b8db241182e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Mon, 17 Aug 2015 17:32:16 +0200 Subject: [PATCH] Change to comply negotiation:^2.0.0 --- lib/Alchemy/Phrasea/Application/Api.php | 2 +- .../Subscriber/ContentNegotiationSubscriber.php | 8 ++------ .../ContentNegotiationServiceProvider.php | 15 +++++++++------ .../ContentNegotiationServiceProviderTest.php | 7 +------ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index cf50758ce2..cdd0f3c747 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -60,7 +60,7 @@ return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) { $request->setFormat(Result::FORMAT_JSONP_EXTENDED, V1::$extendedContentTypes['jsonp']); $request->setFormat(Result::FORMAT_JSONP, array('text/javascript', 'application/javascript')); - $format = $app['format.negotiator']->getBest( + $format = $app['negotiator']->getBest( $request->headers->get('accept', 'application/json'), array_merge( ['application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'], diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php index 9e11b71cdd..b3fd5ae24c 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php @@ -14,11 +14,7 @@ namespace Alchemy\Phrasea\Core\Event\Subscriber; use Alchemy\Phrasea\Application; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; class ContentNegotiationSubscriber implements EventSubscriberInterface { @@ -38,8 +34,8 @@ class ContentNegotiationSubscriber implements EventSubscriberInterface public function onKernelRequest(GetResponseEvent $event) { - $priorities = array('text/html', 'application/json', '*/*'); - $format = $this->app['format.negotiator']->getBest($event->getRequest()->headers->get('accept', '*/*'), $priorities); + $priorities = array('text/html', 'application/json'); + $format = $this->app['negotiator']->getBest($event->getRequest()->headers->get('accept', '*/*'), $priorities); if (null === $format) { $this->app->abort(406, 'Not acceptable'); diff --git a/lib/Alchemy/Phrasea/Core/Provider/ContentNegotiationServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/ContentNegotiationServiceProvider.php index 54e38cf88a..a2f397e81a 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/ContentNegotiationServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/ContentNegotiationServiceProvider.php @@ -11,7 +11,8 @@ namespace Alchemy\Phrasea\Core\Provider; -use Negotiation\FormatNegotiator; +use Negotiation\CharsetNegotiator; +use Negotiation\EncodingNegotiator; use Negotiation\LanguageNegotiator; use Negotiation\Negotiator; use Silex\Application; @@ -21,15 +22,17 @@ class ContentNegotiationServiceProvider implements ServiceProviderInterface { public function register(Application $app) { - $app['negotiator'] = $app->share(function ($app) { + $app['negotiator'] = $app->share(function () { return new Negotiator(); }); - $app['format.negotiator'] = $app->share(function ($app) { - return new FormatNegotiator(); + $app['charset.negotiator'] = $app->share(function () { + return new CharsetNegotiator(); }); - - $app['langage.negotiator'] = $app->share(function ($app) { + $app['encoding.negotiator'] = $app->share(function () { + return new EncodingNegotiator(); + }); + $app['language.negotiator'] = $app->share(function () { return new LanguageNegotiator(); }); } diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/ContentNegotiationServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/ContentNegotiationServiceProviderTest.php index c1a5bb1d80..175ffca81b 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/ContentNegotiationServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/ContentNegotiationServiceProviderTest.php @@ -21,12 +21,7 @@ class classContentNegotiationServiceProviderTest extends ServiceProviderTestCase ), array( 'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider', - 'format.negotiator', - 'Negotiation\FormatNegotiator' - ), - array( - 'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider', - 'langage.negotiator', + 'language.negotiator', 'Negotiation\LanguageNegotiator' ) );