3 namespace Drupal\file_mdm\Plugin\FileMetadata;
5 use Drupal\file_mdm\FileMetadataException;
8 * FileMetadata plugin for getimagesize.
11 * id = "getimagesize",
12 * title = @Translation("Getimagesize"),
13 * help = @Translation("File metadata plugin for PHP getimagesize()."),
16 class GetImageSize extends FileMetadataPluginBase {
21 public function getSupportedKeys($options = NULL) {
22 return [0, 1, 2, 3, 'mime', 'channels', 'bits'];
28 protected function doGetMetadataFromFile() {
29 if ($data = @getimagesize($this->getLocalTempPath())) {
38 * Validates a file metadata key.
41 * TRUE if the key is valid.
43 * @throws \Drupal\file_mdm\FileMetadataException
44 * In case the key is invalid.
46 protected function validateKey($key, $method) {
47 if (!is_int($key) && !is_string($key)) {
48 throw new FileMetadataException("Invalid metadata key specified", $this->getPluginId(), $method);
50 if (!in_array($key, $this->getSupportedKeys(), TRUE)) {
51 throw new FileMetadataException("Invalid metadata key '{$key}' specified", $this->getPluginId(), $method);
59 protected function doGetMetadata($key = NULL) {
61 return $this->metadata;
64 $this->validateKey($key, __FUNCTION__);
65 return isset($this->metadata[$key]) ? $this->metadata[$key] : NULL;
72 protected function doSetMetadata($key, $value) {
73 $this->validateKey($key, __FUNCTION__);
74 $this->metadata[$key] = $value;
81 protected function doRemoveMetadata($key) {
82 $this->validateKey($key, __FUNCTION__);
83 if (isset($this->metadata[$key])) {
84 unset($this->metadata[$key]);