PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/concreteOLD/libraries/3rdparty/Zend/Validate/File/IsCompressed.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 149 lines | 86 code | 12 blank | 51 comment | 6 complexity | 0ebbfd4fe8307951fde72171977c4372 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Validate
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: IsCompressed.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * @see Zend_Validate_File_MimeType
  23. */
  24. require_once 'Zend/Validate/File/MimeType.php';
  25. /**
  26. * Validator which checks if the file already exists in the directory
  27. *
  28. * @category Zend
  29. * @package Zend_Validate
  30. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType
  34. {
  35. /**
  36. * @const string Error constants
  37. */
  38. const FALSE_TYPE = 'fileIsCompressedFalseType';
  39. const NOT_DETECTED = 'fileIsCompressedNotDetected';
  40. const NOT_READABLE = 'fileIsCompressedNotReadable';
  41. /**
  42. * @var array Error message templates
  43. */
  44. protected $_messageTemplates = array(
  45. self::FALSE_TYPE => "File '%value%' is not compressed, '%type%' detected",
  46. self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected",
  47. self::NOT_READABLE => "File '%value%' is not readable or does not exist",
  48. );
  49. /**
  50. * Sets validator options
  51. *
  52. * @param string|array|Zend_Config $compression
  53. * @return void
  54. */
  55. public function __construct($mimetype = array())
  56. {
  57. if ($mimetype instanceof Zend_Config) {
  58. $mimetype = $mimetype->toArray();
  59. }
  60. $temp = array();
  61. // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
  62. $default = array(
  63. 'application/arj',
  64. 'application/gnutar',
  65. 'application/lha',
  66. 'application/lzx',
  67. 'application/vnd.ms-cab-compressed',
  68. 'application/x-ace-compressed',
  69. 'application/x-arc',
  70. 'application/x-archive',
  71. 'application/x-arj',
  72. 'application/x-bzip',
  73. 'application/x-bzip2',
  74. 'application/x-cab-compressed',
  75. 'application/x-compress',
  76. 'application/x-compressed',
  77. 'application/x-cpio',
  78. 'application/x-debian-package',
  79. 'application/x-eet',
  80. 'application/x-gzip',
  81. 'application/x-java-pack200',
  82. 'application/x-lha',
  83. 'application/x-lharc',
  84. 'application/x-lzh',
  85. 'application/x-lzma',
  86. 'application/x-lzx',
  87. 'application/x-rar',
  88. 'application/x-sit',
  89. 'application/x-stuffit',
  90. 'application/x-tar',
  91. 'application/zip',
  92. 'application/zoo',
  93. 'multipart/x-gzip',
  94. );
  95. if (is_array($mimetype)) {
  96. $temp = $mimetype;
  97. if (array_key_exists('magicfile', $temp)) {
  98. unset($temp['magicfile']);
  99. }
  100. if (array_key_exists('headerCheck', $temp)) {
  101. unset($temp['headerCheck']);
  102. }
  103. if (empty($temp)) {
  104. $mimetype += $default;
  105. }
  106. }
  107. if (empty($mimetype)) {
  108. $mimetype = $default;
  109. }
  110. parent::__construct($mimetype);
  111. }
  112. /**
  113. * Throws an error of the given type
  114. * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2
  115. *
  116. * @param string $file
  117. * @param string $errorType
  118. * @return false
  119. */
  120. protected function _throw($file, $errorType)
  121. {
  122. $this->_value = $file['name'];
  123. switch($errorType) {
  124. case Zend_Validate_File_MimeType::FALSE_TYPE :
  125. $errorType = self::FALSE_TYPE;
  126. break;
  127. case Zend_Validate_File_MimeType::NOT_DETECTED :
  128. $errorType = self::NOT_DETECTED;
  129. break;
  130. case Zend_Validate_File_MimeType::NOT_READABLE :
  131. $errorType = self::NOT_READABLE;
  132. break;
  133. }
  134. $this->_error($errorType);
  135. return false;
  136. }
  137. }