mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 10:23:17 +00:00
Change to comply negotiation:^2.0.0
This commit is contained in:
@@ -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');
|
$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['json'] as $priorities[]);
|
||||||
foreach (\API_V1_adapter::$extendedContentTypes['yaml'] 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
|
// throw unacceptable http error if API can not handle asked format
|
||||||
if (null === $format) {
|
if (null === $format) {
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ class ContentNegotiationSubscriber implements EventSubscriberInterface
|
|||||||
|
|
||||||
public function onKernelRequest(GetResponseEvent $event)
|
public function onKernelRequest(GetResponseEvent $event)
|
||||||
{
|
{
|
||||||
$priorities = array('text/html', 'application/json', '*/*');
|
$priorities = array('text/html', 'application/json');
|
||||||
$format = $this->app['format.negociator']->getBest($event->getRequest()->headers->get('accept', '*/*'), $priorities);
|
$format = $this->app['negotiator']->getBest($event->getRequest()->headers->get('accept', '*/*'), $priorities);
|
||||||
|
|
||||||
if (null === $format) {
|
if (null === $format) {
|
||||||
$this->app->abort(406, 'Not acceptable');
|
$this->app->abort(406, 'Not acceptable');
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Core\Provider;
|
namespace Alchemy\Phrasea\Core\Provider;
|
||||||
|
|
||||||
use Negotiation\FormatNegotiator;
|
use Negotiation\CharsetNegotiator;
|
||||||
|
use Negotiation\EncodingNegotiator;
|
||||||
use Negotiation\LanguageNegotiator;
|
use Negotiation\LanguageNegotiator;
|
||||||
use Negotiation\Negotiator;
|
use Negotiation\Negotiator;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
@@ -21,15 +22,17 @@ class ContentNegotiationServiceProvider implements ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['negociator'] = $app->share(function ($app) {
|
$app['negotiator'] = $app->share(function () {
|
||||||
return new Negotiator();
|
return new Negotiator();
|
||||||
});
|
});
|
||||||
|
|
||||||
$app['format.negociator'] = $app->share(function ($app) {
|
$app['charset.negotiator'] = $app->share(function () {
|
||||||
return new FormatNegotiator();
|
return new CharsetNegotiator();
|
||||||
});
|
});
|
||||||
|
$app['encoding.negotiator'] = $app->share(function () {
|
||||||
$app['langage.negociator'] = $app->share(function ($app) {
|
return new EncodingNegotiator();
|
||||||
|
});
|
||||||
|
$app['language.negotiator'] = $app->share(function () {
|
||||||
return new LanguageNegotiator();
|
return new LanguageNegotiator();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,17 +12,12 @@ class classContentNegotiationServiceProviderTest extends ServiceProviderTestCase
|
|||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider',
|
'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider',
|
||||||
'negociator',
|
'negotiator',
|
||||||
'Negotiation\Negotiator',
|
'Negotiation\Negotiator',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider',
|
'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider',
|
||||||
'format.negociator',
|
'language.negotiator',
|
||||||
'Negotiation\FormatNegotiator'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'Alchemy\Phrasea\Core\Provider\ContentNegotiationServiceProvider',
|
|
||||||
'langage.negociator',
|
|
||||||
'Negotiation\LanguageNegotiator'
|
'Negotiation\LanguageNegotiator'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user