foldershare-8.x-1.2/src/Entity/FolderShareTraits/GetSetMimeTrait.php

src/Entity/FolderShareTraits/GetSetMimeTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
 
namespace Drupal\foldershare\Entity\FolderShareTraits;
 
/**
 * Get/set FolderShare entity mime field.
 *
 * This trait includes get methods for FolderShare entity mime field.
 *
 * <B>Internal trait</B>
 * This trait is internal to the FolderShare module and used to define
 * features of the FolderShare entity class. It is a mechanism to group
 * functionality to improve code management.
 *
 * @ingroup foldershare
 */
trait GetSetMimeTrait {
 
  /*---------------------------------------------------------------------
   *
   * Mime field.
   *
   *---------------------------------------------------------------------*/
 
  /**
   * {@inheritdoc}
   */
  public function getMimeType() {
    return $this->get('mime')->value;
  }
 
  /**
   * Sets the item's MIME type.
   *
   * <B>This method is internal and strictly for use by the FolderShare
   * module itself.</B>
   *
   * The MIME type is not validated. The caller should insure that it is
   * not empty and has a legal form. When this item is a file or image,
   * the MIME type should match that of the underlying stored file or image.
   * This is often done by using the MIME type guesser service and the
   * file's extension.
   *
   * For folders, FOLDER_MIME should be used since there is no file to
   * guess from and no standard MIME type.
   *
   * The caller must call save() for the change to take effect.
   *
   * <B>Process locks</B>
   * This method does not lock access. The caller should lock around changes
   * to the entity.
   *
   * @param string $mime
   *   The new MIME type. The value is not validated but is expected to
   *   be a properly formed MIME type.
   *
   * @see ::getMimeType()
   * @see ::isMimeTypeImage()
   * @see \Drupal\file\FileInterface::setMimeType()
   */
  private function setMimeType(string $mime) {
    $this->set('mime', $mime);
  }
 
  /*---------------------------------------------------------------------
   *
   * Mime utilities.
   *
   *---------------------------------------------------------------------*/
 
  /**
   * Returns TRUE if a MIME type refers to an image type.
   *
   * MIME types are a concatenation of a top-level type name, a "/",
   * and a subtype name with an optional prefix, suffix, and parameters.
   * The top-level type name is one of several well-known names:
   * - application.
   * - audio.
   * - example.
   * - font.
   * - image.
   * - message.
   * - model.
   * - multipart.
   * - text.
   * - video.
   *
   * This function returns TRUE if the top-level type name is 'image'.
   *
   * @param string $mimeType
   *   The MIME type to check.
   *
   * @return bool
   *   Returns TRUE if the MIME type is for an image, and FALSE otherwise.
   */
  public static function isMimeTypeImage(string $mimeType) {
    list($topLevel,) = explode('/', $mimeType, 2);
    return ($topLevel === 'image');
  }
 
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc