Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IsCompressed.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Validate/File/MimeType.php';
26 
36 {
40  const FALSE_TYPE = 'fileIsCompressedFalseType';
41  const NOT_DETECTED = 'fileIsCompressedNotDetected';
42  const NOT_READABLE = 'fileIsCompressedNotReadable';
43 
47  protected $_messageTemplates = array(
48  self::FALSE_TYPE => "File '%value%' is not compressed, '%type%' detected",
49  self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected",
50  self::NOT_READABLE => "File '%value%' is not readable or does not exist",
51  );
52 
58  public function __construct($mimetype = array())
59  {
60  if ($mimetype instanceof Zend_Config) {
61  $mimetype = $mimetype->toArray();
62  }
63 
64  $temp = array();
65  // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
66  $default = array(
67  'application/arj',
68  'application/gnutar',
69  'application/lha',
70  'application/lzx',
71  'application/vnd.ms-cab-compressed',
72  'application/x-ace-compressed',
73  'application/x-arc',
74  'application/x-archive',
75  'application/x-arj',
76  'application/x-bzip',
77  'application/x-bzip2',
78  'application/x-cab-compressed',
79  'application/x-compress',
80  'application/x-compressed',
81  'application/x-cpio',
82  'application/x-debian-package',
83  'application/x-eet',
84  'application/x-gzip',
85  'application/x-java-pack200',
86  'application/x-lha',
87  'application/x-lharc',
88  'application/x-lzh',
89  'application/x-lzma',
90  'application/x-lzx',
91  'application/x-rar',
92  'application/x-sit',
93  'application/x-stuffit',
94  'application/x-tar',
95  'application/zip',
96  'application/x-zip',
97  'application/zoo',
98  'multipart/x-gzip',
99  );
100 
101  if (is_array($mimetype)) {
102  $temp = $mimetype;
103  if (array_key_exists('magicfile', $temp)) {
104  unset($temp['magicfile']);
105  }
106 
107  if (array_key_exists('headerCheck', $temp)) {
108  unset($temp['headerCheck']);
109  }
110 
111  if (empty($temp)) {
112  $mimetype += $default;
113  }
114  }
115 
116  if (empty($mimetype)) {
117  $mimetype = $default;
118  }
119 
120  parent::__construct($mimetype);
121  }
122 
131  protected function _throw($file, $errorType)
132  {
133  $this->_value = $file['name'];
134  switch($errorType) {
136  $errorType = self::FALSE_TYPE;
137  break;
139  $errorType = self::NOT_DETECTED;
140  break;
142  $errorType = self::NOT_READABLE;
143  break;
144  }
145 
146  $this->_error($errorType);
147  return false;
148  }
149 }
_error($messageKey, $value=null)
Definition: Abstract.php:284
__construct($mimetype=array())