comparison core/modules/jsonapi/src/JsonapiServiceProvider.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
1 <?php
2
3 namespace Drupal\jsonapi;
4
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
7 use Drupal\Core\DependencyInjection\ServiceProviderInterface;
8 use Drupal\Core\StackMiddleware\NegotiationMiddleware;
9 use Drupal\jsonapi\DependencyInjection\Compiler\RegisterSerializationClassesCompilerPass;
10
11 /**
12 * Adds 'api_json' as known format and prevents its use in the REST module.
13 *
14 * @internal JSON:API maintains no PHP API since its API is the HTTP API. This
15 * class may change at any time and this will break any dependencies on it.
16 *
17 * @see https://www.drupal.org/project/jsonapi/issues/3032787
18 * @see jsonapi.api.php
19 */
20 class JsonapiServiceProvider implements ServiceModifierInterface, ServiceProviderInterface {
21
22 /**
23 * {@inheritdoc}
24 */
25 public function alter(ContainerBuilder $container) {
26 if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), NegotiationMiddleware::class, TRUE)) {
27 // @see http://www.iana.org/assignments/media-types/application/vnd.api+json
28 $container->getDefinition('http_middleware.negotiation')
29 ->addMethodCall('registerFormat', [
30 'api_json',
31 ['application/vnd.api+json'],
32 ]);
33 }
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function register(ContainerBuilder $container) {
40 $container->addCompilerPass(new RegisterSerializationClassesCompilerPass());
41 }
42
43 }