You are here

class GetImageSize in File metadata manager 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/FileMetadata/GetImageSize.php \Drupal\file_mdm\Plugin\FileMetadata\GetImageSize

FileMetadata plugin for getimagesize.

Plugin annotation


@FileMetadata(
  id = "getimagesize",
  title = @Translation("Getimagesize"),
  help = @Translation("File metadata plugin for PHP getimagesize()."),
)

Hierarchy

Expanded class hierarchy of GetImageSize

File

src/Plugin/FileMetadata/GetImageSize.php, line 16

Namespace

Drupal\file_mdm\Plugin\FileMetadata
View source
class GetImageSize extends FileMetadataPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getSupportedKeys($options = NULL) {
    return [
      0,
      1,
      2,
      3,
      'mime',
      'channels',
      'bits',
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function doGetMetadataFromFile() {
    if ($data = @getimagesize($this
      ->getLocalTempPath())) {
      return $data;
    }
    else {
      return NULL;
    }
  }

  /**
   * Validates a file metadata key.
   *
   * @return bool
   *   TRUE if the key is valid.
   *
   * @throws \Drupal\file_mdm\FileMetadataException
   *   In case the key is invalid.
   */
  protected function validateKey($key, $method) {
    if (!is_int($key) && !is_string($key)) {
      throw new FileMetadataException("Invalid metadata key specified", $this
        ->getPluginId(), $method);
    }
    if (!in_array($key, $this
      ->getSupportedKeys(), TRUE)) {
      throw new FileMetadataException("Invalid metadata key '{$key}' specified", $this
        ->getPluginId(), $method);
    }
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  protected function doGetMetadata($key = NULL) {
    if ($key === NULL) {
      return $this->metadata;
    }
    else {
      $this
        ->validateKey($key, __FUNCTION__);
      return isset($this->metadata[$key]) ? $this->metadata[$key] : NULL;
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function doSetMetadata($key, $value) {
    $this
      ->validateKey($key, __FUNCTION__);
    $this->metadata[$key] = $value;
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  protected function doRemoveMetadata($key) {
    $this
      ->validateKey($key, __FUNCTION__);
    if (isset($this->metadata[$key])) {
      unset($this->metadata[$key]);
    }
    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
FileMetadataPluginBase::$cache protected property The cache service.
FileMetadataPluginBase::$configFactory protected property The config factory.
FileMetadataPluginBase::$hash protected property The hash used to reference the URI.
FileMetadataPluginBase::$hasMetadataChangedFromCacheVersion protected property Track if file metadata on cache needs update.
FileMetadataPluginBase::$hasMetadataChangedFromFileVersion protected property Track if metadata has been changed from version on file.
FileMetadataPluginBase::$isMetadataLoaded protected property The metadata loading status.
FileMetadataPluginBase::$localTempPath protected property The local filesystem path to the file.
FileMetadataPluginBase::$metadata protected property The metadata of the file.
FileMetadataPluginBase::$uri protected property The URI of the file.
FileMetadataPluginBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
FileMetadataPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
FileMetadataPluginBase::defaultConfiguration public static function Gets default configuration for this plugin. Overrides FileMetadataPluginInterface::defaultConfiguration
FileMetadataPluginBase::deleteCachedMetadata public function Removes cached metadata for file at URI. Overrides FileMetadataPluginInterface::deleteCachedMetadata
FileMetadataPluginBase::doSaveMetadataToFile protected function Saves metadata to file at URI. 1
FileMetadataPluginBase::getConfigObject protected function Gets the configuration object for this plugin.
FileMetadataPluginBase::getLocalTempPath public function Gets the local filesystem path to the file. Overrides FileMetadataPluginInterface::getLocalTempPath
FileMetadataPluginBase::getMetadata public function Gets a metadata element. Overrides FileMetadataPluginInterface::getMetadata
FileMetadataPluginBase::getMetadataToCache protected function Gets metadata to save to cache.
FileMetadataPluginBase::getUri public function Gets the URI of the file. Overrides FileMetadataPluginInterface::getUri
FileMetadataPluginBase::isMetadataLoaded public function Checks if file metadata has been already loaded. Overrides FileMetadataPluginInterface::isMetadataLoaded
FileMetadataPluginBase::isSaveToFileSupported public function Determines if plugin is capable of writing metadata to files. Overrides FileMetadataPluginInterface::isSaveToFileSupported 1
FileMetadataPluginBase::isUriFileMetadataCacheable protected function Checks if file metadata should be cached.
FileMetadataPluginBase::loadMetadata public function Loads file metadata from an in-memory object/array. Overrides FileMetadataPluginInterface::loadMetadata
FileMetadataPluginBase::loadMetadataFromCache public function Loads file metadata from a cache entry. Overrides FileMetadataPluginInterface::loadMetadataFromCache
FileMetadataPluginBase::loadMetadataFromFile public function Loads file metadata from the file at URI/local path. Overrides FileMetadataPluginInterface::loadMetadataFromFile
FileMetadataPluginBase::removeMetadata public function Removes a metadata element. Overrides FileMetadataPluginInterface::removeMetadata
FileMetadataPluginBase::saveMetadataToCache public function Caches metadata for file at URI. Overrides FileMetadataPluginInterface::saveMetadataToCache
FileMetadataPluginBase::saveMetadataToFile public function Saves metadata to file at URI. Overrides FileMetadataPluginInterface::saveMetadataToFile
FileMetadataPluginBase::setHash public function Sets the hash used to reference the URI by the metadata manager. Overrides FileMetadataPluginInterface::setHash
FileMetadataPluginBase::setLocalTempPath public function Sets the local filesystem path to the file. Overrides FileMetadataPluginInterface::setLocalTempPath
FileMetadataPluginBase::setMetadata public function Sets a metadata element. Overrides FileMetadataPluginInterface::setMetadata
FileMetadataPluginBase::setUri public function Sets the URI of the file. Overrides FileMetadataPluginInterface::setUri
FileMetadataPluginBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
FileMetadataPluginBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
FileMetadataPluginBase::__construct public function Constructs a FileMetadataPluginBase plugin. Overrides PluginBase::__construct 1
GetImageSize::doGetMetadata protected function Gets a metadata element. Overrides FileMetadataPluginBase::doGetMetadata
GetImageSize::doGetMetadataFromFile protected function Gets file metadata from the file at URI/local path. Overrides FileMetadataPluginBase::doGetMetadataFromFile
GetImageSize::doRemoveMetadata protected function Removes a metadata element. Overrides FileMetadataPluginBase::doRemoveMetadata
GetImageSize::doSetMetadata protected function Sets a metadata element. Overrides FileMetadataPluginBase::doSetMetadata
GetImageSize::getSupportedKeys public function Returns a list of metadata keys supported by the plugin. Overrides FileMetadataPluginInterface::getSupportedKeys
GetImageSize::validateKey protected function Validates a file metadata key.
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.
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.