You are here

public function ExifTagMapper::resolveKeyToIfdAndTag in File metadata manager 8.2

Same name and namespace in other branches
  1. 8 file_mdm_exif/src/ExifTagMapper.php \Drupal\file_mdm_exif\ExifTagMapper::resolveKeyToIfdAndTag()

Resolves a metadata 'key' to the default EXIF IFD and TAG.

Parameters

string|array $key: A metadata 'key' as passed in by the file metadata manager. It can be a string, in which case the default IFD and TAG are returned. If it is an array, then the first and the second array elements define respectively the IFD and the TAG requested. IFD and TAG can be strings, in which case they are converted to EXIF integer identifiers, or integers, in which case they are returned as such.

Return value

array An associative array with the following keys: 'ifd' - the IFD EXIF integer identifier. 'tag' - the TAG EXIF integer identifier.

Throws

\Drupal\file_mdm\FileMetadataException When wrong argument is passed, or if the IFD/TAG could not be found.

Overrides ExifTagMapperInterface::resolveKeyToIfdAndTag

File

file_mdm_exif/src/ExifTagMapper.php, line 95

Class

ExifTagMapper
Provides a mapping service for EXIF ifds and tags.

Namespace

Drupal\file_mdm_exif

Code

public function resolveKeyToIfdAndTag($key) {
  if ($key === NULL) {
    throw new FileMetadataException('Missing $key argument', NULL, __METHOD__);
  }
  if (is_string($key)) {
    $tag = $this
      ->stringToTag($key);
    return [
      'ifd' => $tag[0],
      'tag' => $tag[1],
    ];
  }
  if (is_array($key)) {
    if (!isset($key[0]) || !isset($key[1])) {
      throw new FileMetadataException('Invalid $key array specified, must have two values', NULL, __METHOD__);
    }

    // Deal with ifd.
    if (is_int($key[0])) {
      $ifd = $key[0];
    }
    elseif (is_string($key[0])) {
      $ifd = $this
        ->stringToIfd($key[0]);
    }
    else {
      throw new FileMetadataException('Invalid EXIF IFD specified, must be a string or an integer', NULL, __METHOD__);
    }

    // Deal with tag.
    if (is_string($key[1])) {
      $tag = $this
        ->stringToTag($key[1])[1];
    }
    elseif (is_int($key[1])) {
      $tag = $key[1];
    }
    else {
      throw new FileMetadataException('Invalid EXIF TAG specified, must be a string or an integer', NULL, __METHOD__);
    }
    return [
      'ifd' => $ifd,
      'tag' => $tag,
    ];
  }
  throw new FileMetadataException('Invalid $key argument, must be a string or an array', NULL, __METHOD__);
}