10000 Fix #1399 by GuilhemN · Pull Request #1400 · FriendsOfSymfony/FOSRestBundle · GitHub
[go: up one dir, main page]

Skip to content

Fix #1399 #1400

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

Merged
merged 1 commit into from
Mar 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions DependencyInjection/FOSRestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ private function loadFormatListener(array $config, XmlFileLoader $loader, Contai
'fos_rest.format_listener.rules',
$config['format_listener']['rules']
);

if ($config['view']['mime_types']['enabled'] && !method_exists(Request::class, 'getMimeTypes')) {
$container->getDefinition('fos_rest.format_negotiator')->addArgument($config['view']['mime_types']['formats']);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion EventListener/FormatListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function onKernelRequest(GetResponseEvent $event)
if (null === $format) {
$accept = $this->formatNegotiator->getBest('');
if (null !== $accept && 0.0 < $accept->getQuality()) {
$format = $request->getFormat($accept->getType());
$format = $request->getFormat($accept->getValue());
if (null !== $format) {
$request->attributes->set('media_type', $accept->getValue());
}
Expand Down
4 changes: 3 additions & 1 deletion EventListener/MimeTypeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function onKernelRequest(GetResponseEvent $event)
} elseif (null !== $request->getMimeType($format)) {
$class = new \ReflectionClass(Request::class);
$properties = $class->getStaticProperties();
$mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
if (isset($properties['formats'][$format])) {
$mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
}
}

$request->setFormat($format, $mimeTypes);
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testCustomHeaderVersion()
'/version?query_version=3.2',
[],
[],
['HTTP_Version-Header' => '2.1', 'HTTP_Accept' => 'application/json;myversion=2.3']
['HTTP_Version-Header' => '2.1', 'HTTP_Accept' => 'application/vnd.foo.api+json;myversion=2.3']
);
$this->assertEquals('{"version":"2.1"}', $this->client->getResponse()->getContent());
}
Expand All @@ -54,7 +54,7 @@ public function testAcceptHeaderVersion()
'/version?query_version=3.2',
[],
[],
['HTTP_Accept' => 'application/json;myversion=2.3']
['HTTP_Accept' => 'application/vnd.foo.api+json;myversion=2.3']
);
$this->assertEquals('{"version":"2.3"}', $this->client->getResponse()->getContent());
}
Expand Down
5 changes: 4 additions & 1 deletion Tests/Functional/app/Version/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ fos_rest:
view:
view_response_listener: true
mime_types:
json: ['application/json', 'application/json;myversion=2.3']
json:
- application/json
- application/vnd.foo.api+json;myversion=2.3
- application/vnd.foo.api+json # Fix for https://github.com/FriendsOfSymfony/FOSRestBundle/issues/1399
versioning:
enabled: true
default_version: 3.4.2
Expand Down
0