File indexing completed on 2024-12-22 05:37:11
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Validate 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Validate_File_MimeType 0024 */ 0025 // require_once 'Zend/Validate/File/MimeType.php'; 0026 0027 /** 0028 * Validator which checks if the file already exists in the directory 0029 * 0030 * @category Zend 0031 * @package Zend_Validate 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType 0036 { 0037 /** 0038 * @const string Error constants 0039 */ 0040 const FALSE_TYPE = 'fileIsCompressedFalseType'; 0041 const NOT_DETECTED = 'fileIsCompressedNotDetected'; 0042 const NOT_READABLE = 'fileIsCompressedNotReadable'; 0043 0044 /** 0045 * @var array Error message templates 0046 */ 0047 protected $_messageTemplates = array( 0048 self::FALSE_TYPE => "File '%value%' is not compressed, '%type%' detected", 0049 self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", 0050 self::NOT_READABLE => "File '%value%' is not readable or does not exist", 0051 ); 0052 0053 /** 0054 * Sets validator options 0055 * 0056 * @param string|array|Zend_Config $mimetype 0057 */ 0058 public function __construct($mimetype = array()) 0059 { 0060 if ($mimetype instanceof Zend_Config) { 0061 $mimetype = $mimetype->toArray(); 0062 } 0063 0064 $temp = array(); 0065 // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen 0066 $default = array( 0067 'application/arj', 0068 'application/gnutar', 0069 'application/lha', 0070 'application/lzx', 0071 'application/vnd.ms-cab-compressed', 0072 'application/x-ace-compressed', 0073 'application/x-arc', 0074 'application/x-archive', 0075 'application/x-arj', 0076 'application/x-bzip', 0077 'application/x-bzip2', 0078 'application/x-cab-compressed', 0079 'application/x-compress', 0080 'application/x-compressed', 0081 'application/x-cpio', 0082 'application/x-debian-package', 0083 'application/x-eet', 0084 'application/x-gzip', 0085 'application/x-java-pack200', 0086 'application/x-lha', 0087 'application/x-lharc', 0088 'application/x-lzh', 0089 'application/x-lzma', 0090 'application/x-lzx', 0091 'application/x-rar', 0092 'application/x-sit', 0093 'application/x-stuffit', 0094 'application/x-tar', 0095 'application/zip', 0096 'application/x-zip', 0097 'application/zoo', 0098 'multipart/x-gzip', 0099 ); 0100 0101 if (is_array($mimetype)) { 0102 $temp = $mimetype; 0103 if (array_key_exists('magicfile', $temp)) { 0104 unset($temp['magicfile']); 0105 } 0106 0107 if (array_key_exists('headerCheck', $temp)) { 0108 unset($temp['headerCheck']); 0109 } 0110 0111 if (empty($temp)) { 0112 $mimetype += $default; 0113 } 0114 } 0115 0116 if (empty($mimetype)) { 0117 $mimetype = $default; 0118 } 0119 0120 parent::__construct($mimetype); 0121 } 0122 0123 /** 0124 * Throws an error of the given type 0125 * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2 0126 * 0127 * @param string $file 0128 * @param string $errorType 0129 * @return false 0130 */ 0131 protected function _throw($file, $errorType) 0132 { 0133 $this->_value = $file['name']; 0134 switch($errorType) { 0135 case Zend_Validate_File_MimeType::FALSE_TYPE : 0136 $errorType = self::FALSE_TYPE; 0137 break; 0138 case Zend_Validate_File_MimeType::NOT_DETECTED : 0139 $errorType = self::NOT_DETECTED; 0140 break; 0141 case Zend_Validate_File_MimeType::NOT_READABLE : 0142 $errorType = self::NOT_READABLE; 0143 break; 0144 } 0145 0146 $this->_error($errorType); 0147 return false; 0148 } 0149 }