You are here

class S3FileSchemeHandler in Acquia Content Hub 8.2

S3 file scheme handler.

Plugin annotation


@FileSchemeHandler(
  id = "s3",
  label = @Translation("Amazon S3 file handler")
)

Hierarchy

Expanded class hierarchy of S3FileSchemeHandler

File

modules/acquia_contenthub_s3/src/Plugin/FileSchemeHandler/S3FileSchemeHandler.php, line 24

Namespace

Drupal\acquia_contenthub_s3\Plugin\FileSchemeHandler
View source
class S3FileSchemeHandler extends PluginBase implements FileSchemeHandlerInterface, ContainerFactoryPluginInterface {

  /**
   * The stream wrapper manager.
   *
   * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
   */
  protected $streamWrapperManager;

  /**
   * The s3fs.settings configuration.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $s3fsConfig;

  /**
   * The s3 file mapper service.
   *
   * @var \Drupal\acquia_contenthub_s3\S3FileMapper
   */
  protected $s3FileMapper;

  /**
   * S3FileSchemeHandler constructor.
   *
   * @param array $configuration
   *   The plugin configuration.
   * @param string $plugin_id
   *   The plugin id.
   * @param mixed $plugin_definition
   *   The definition.
   * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
   *   The stream wrapper manager service.
   * @param \Drupal\Core\Config\Config $config
   *   The s3fs.settings configuration object.
   * @param \Drupal\acquia_contenthub_s3\S3FileMapper $s3_file_mapper
   *   The s3 file mapper service.
   */
  public function __construct(array $configuration, string $plugin_id, $plugin_definition, StreamWrapperManagerInterface $stream_wrapper_manager, Config $config, S3FileMapper $s3_file_mapper) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->streamWrapperManager = $stream_wrapper_manager;
    $this->s3fsConfig = $config;
    $this->s3FileMapper = $s3_file_mapper;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('stream_wrapper_manager'), $container
      ->get('config.factory')
      ->get('s3fs.settings'), $container
      ->get('acquia_contenthub_s3.file_mapper'));
  }

  /**
   * {@inheritdoc}
   *
   * @throws \Exception
   */
  public function addAttributes(CDFObject $object, FileInterface $file) {
    $uri = $file
      ->getFileUri();
    $streamWrapper = $this->streamWrapperManager
      ->getViaUri($uri);
    $url = $streamWrapper
      ->getExternalUrl();
    $object
      ->addAttribute('file_scheme', CDFAttribute::TYPE_STRING, 's3');
    $object
      ->addAttribute('file_location', CDFAttribute::TYPE_STRING, $url);
    $object
      ->addAttribute('file_uri', CDFAttribute::TYPE_STRING, $uri);
    $object
      ->addAttribute('ach_s3_bucket', CDFAttribute::TYPE_STRING, $this->s3fsConfig
      ->get('bucket'));
    $object
      ->addAttribute('ach_s3_source', CDFAttribute::TYPE_STRING, $this->s3fsConfig
      ->get('root_folder'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFile(CDFObject $object) {

    // No import needed, file is served from s3 bucket.
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
S3FileSchemeHandler::$s3FileMapper protected property The s3 file mapper service.
S3FileSchemeHandler::$s3fsConfig protected property The s3fs.settings configuration.
S3FileSchemeHandler::$streamWrapperManager protected property The stream wrapper manager.
S3FileSchemeHandler::addAttributes public function Overrides FileSchemeHandlerInterface::addAttributes
S3FileSchemeHandler::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
S3FileSchemeHandler::getFile public function Makes file available to Drupal through the correct stream wrapper. Overrides FileSchemeHandlerInterface::getFile
S3FileSchemeHandler::__construct public function S3FileSchemeHandler constructor. Overrides PluginBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.