From 54913d5e79351cadb77544ea27728e4395f649e5 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 | 4 ++-- .../ContentNegotiationServiceProvider.php | 15 +++++++++------ .../ContentNegotiationServiceProviderTest.php | 9 ++------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index 38612ca7e7..06eb81f924 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -53,7 +53,7 @@ return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) { $priorities = array('application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'); foreach (\API_V1_adapter::$extendedContentTypes['json'] as $priorities[]); foreach (\API_V1_adapter::$extendedContentTypes['yaml'] as $priorities[]); - $format = $app['format.negociator']->getBest($request->headers->get('accept', 'application/json') ,$priorities); + $format = $app['negotiator']->getBest($request->headers->get('accept', 'application/json') ,$priorities); // throw unacceptable http error if API can not handle asked format if (null === $format) { diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php index 305fe27ddb..b38d598f27 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php @@ -38,8 +38,8 @@ class ContentNegotiationSubscriber implements EventSubscriberInterface public function onKernelRequest(GetResponseEvent $event) { - $priorities = array('text/html', 'application/json', '*/*'); - $format = $this->app['format.negociator']->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 c702f2d190..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['negociator'] = $app->share(function ($app) { + $app['negotiator'] = $app->share(function () { return new Negotiator(); }); - $app['format.negociator'] = $app->share(function ($app) { - return new FormatNegotiator(); + $app['charset.negotiator'] = $app->share(function () { + return new CharsetNegotiator(); }); - - $app['langage.negociator'] = $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 79defe4d14..52b6cbf9e4 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/ContentNegotiationServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/ContentNegotiationServiceProviderTest.php @@ -12,17 +12,12 @@ class classContentNegotiationServiceProviderTest extends ServiceProviderTestCase return array( array( 'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider', - 'negociator', + 'negotiator', 'Negotiation\Negotiator', ), array( 'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider', - 'format.negociator', - 'Negotiation\FormatNegotiator' - ), - array( - 'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider', - 'langage.negociator', + 'language.negotiator', 'Negotiation\LanguageNegotiator' ) );