OpenerResolver.php

Same filename in other branches
  1. 9 core/modules/media_library/src/OpenerResolver.php
  2. 10 core/modules/media_library/src/OpenerResolver.php
  3. 11.x core/modules/media_library/src/OpenerResolver.php

Namespace

Drupal\media_library

File

core/modules/media_library/src/OpenerResolver.php

View source
<?php

namespace Drupal\media_library;

use Symfony\Component\DependencyInjection\ContainerAwareTrait;

/**
 * Defines a class to get media library openers from the container.
 *
 * This is intended to be a very thin interface-verifying wrapper around
 * services which implement \Drupal\media_library\MediaLibraryOpenerInterface.
 * It is not an API and should not be extended or used by code that does not
 * interact with the Media Library module.
 *
 * @internal
 *   This service is an internal part of the modal media library dialog and
 *   does not provide any extension points or public API.
 */
class OpenerResolver implements OpenerResolverInterface {
    use ContainerAwareTrait;
    
    /**
     * {@inheritdoc}
     */
    public function get(MediaLibraryState $state) {
        $service_id = $state->getOpenerId();
        $service = $this->container
            ->get($service_id);
        if ($service instanceof MediaLibraryOpenerInterface) {
            return $service;
        }
        throw new \RuntimeException("{$service_id} must be an instance of " . MediaLibraryOpenerInterface::class);
    }

}

Classes

Title Deprecated Summary
OpenerResolver Defines a class to get media library openers from the container.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.