You are here

final class JsonapiHypermediaServiceProvider in JSON:API Hypermedia 8

Class JsonApiHypermediaServiceProvider.

@internal

Hierarchy

Expanded class hierarchy of JsonapiHypermediaServiceProvider

File

src/JsonapiHypermediaServiceProvider.php, line 15

Namespace

Drupal\jsonapi_hypermedia
View source
final class JsonapiHypermediaServiceProvider extends ServiceProviderBase {
  use PriorityTaggedServiceTrait;

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {

    // Enable normalizers in the "src-impostor-normalizers" directory to be
    // within the \Drupal\jsonapi\Normalizer namespace in order to circumvent
    // the encapsulation enforced by
    // \Drupal\jsonapi\Serializer\Serializer::__construct().
    $container_namespaces = $container
      ->getParameter('container.namespaces');
    $container_modules = $container
      ->getParameter('container.modules');
    $impostor_path = dirname($container_modules['jsonapi_hypermedia']['pathname']) . '/src/Normalizer/JsonapiHypermediaImpostor';
    $container_namespaces['Drupal\\jsonapi\\Normalizer\\JsonapiHypermediaImpostor'][] = $impostor_path;
    $container
      ->getDefinition('serializer.normalizer.link_collection.jsonapi_hypermedia')
      ->setFile($impostor_path . '/JsonapiHypermediaLinkCollectionNormalizer.php');
    $container
      ->setParameter('container.namespaces', $container_namespaces);
    $definition = $container
      ->getDefinition('serializer.normalizer.link_collection.jsonapi_hypermedia');
    foreach ($this
      ->findAndSortTaggedServices('jsonapi_hypermedia_provider', $container) as $id) {
      $definition
        ->addMethodCall('addHypermediaProvider', [
        new Reference($id),
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JsonapiHypermediaServiceProvider::alter public function Modifies existing service definitions. Overrides ServiceProviderBase::alter
ServiceProviderBase::register public function Registers services to the container. Overrides ServiceProviderInterface::register 1