diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index d8b86ac541..b1d6b04425 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -51,11 +51,14 @@ 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')); - // handle content negociation - $priorities = array('application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'); - foreach (V1::$extendedContentTypes['json'] as $priorities[]); - foreach (V1::$extendedContentTypes['yaml'] as $priorities[]); - $format = $app['format.negociator']->getBest($request->headers->get('accept', 'application/json') ,$priorities); + $format = $app['format.negotiator']->getBest( + $request->headers->get('accept', 'application/json'), + array_merge( + ['application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'], + V1::$extendedContentTypes['json'], + V1::$extendedContentTypes['yaml'] + ) + ); // 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..9e11b71cdd 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/ContentNegotiationSubscriber.php @@ -39,7 +39,7 @@ 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); + $format = $this->app['format.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..54e38cf88a 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/ContentNegotiationServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/ContentNegotiationServiceProvider.php @@ -21,15 +21,15 @@ class ContentNegotiationServiceProvider implements ServiceProviderInterface { public function register(Application $app) { - $app['negociator'] = $app->share(function ($app) { + $app['negotiator'] = $app->share(function ($app) { return new Negotiator(); }); - $app['format.negociator'] = $app->share(function ($app) { + $app['format.negotiator'] = $app->share(function ($app) { return new FormatNegotiator(); }); - $app['langage.negociator'] = $app->share(function ($app) { + $app['langage.negotiator'] = $app->share(function ($app) { 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..c0bdde5845 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/ContentNegotiationServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/ContentNegotiationServiceProviderTest.php @@ -12,17 +12,17 @@ class classContentNegotiationServiceProviderTest extends ServiceProviderTestCase return array( array( 'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider', - 'negociator', + 'negotiator', 'Negotiation\Negotiator', ), array( 'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider', - 'format.negociator', + 'format.negotiator', 'Negotiation\FormatNegotiator' ), array( 'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider', - 'langage.negociator', + 'langage.negotiator', 'Negotiation\LanguageNegotiator' ) );