酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

267 lines
6.1 KiB

  1. <?php
  2. namespace PhpZip\Model;
  3. use PhpZip\Constants\ZipCompressionMethod;
  4. use PhpZip\Constants\ZipEncryptionMethod;
  5. use PhpZip\Constants\ZipPlatform;
  6. use PhpZip\Util\FileAttribUtil;
  7. use PhpZip\Util\FilesUtil;
  8. /**
  9. * Zip info.
  10. *
  11. * @author Ne-Lexa alexey@nelexa.ru
  12. * @license MIT
  13. *
  14. * @deprecated Use ZipEntry
  15. */
  16. class ZipInfo
  17. {
  18. /** @var ZipEntry */
  19. private $entry;
  20. /**
  21. * ZipInfo constructor.
  22. *
  23. * @param ZipEntry $entry
  24. */
  25. public function __construct(ZipEntry $entry)
  26. {
  27. $this->entry = $entry;
  28. }
  29. /**
  30. * @param ZipEntry $entry
  31. *
  32. * @return string
  33. *
  34. * @deprecated Use {@see ZipPlatform::getPlatformName()}
  35. */
  36. public static function getPlatformName(ZipEntry $entry)
  37. {
  38. return ZipPlatform::getPlatformName($entry->getExtractedOS());
  39. }
  40. /**
  41. * @return string
  42. */
  43. public function getName()
  44. {
  45. return $this->entry->getName();
  46. }
  47. /**
  48. * @return bool
  49. */
  50. public function isFolder()
  51. {
  52. return $this->entry->isDirectory();
  53. }
  54. /**
  55. * @return int
  56. */
  57. public function getSize()
  58. {
  59. return $this->entry->getUncompressedSize();
  60. }
  61. /**
  62. * @return int
  63. */
  64. public function getCompressedSize()
  65. {
  66. return $this->entry->getCompressedSize();
  67. }
  68. /**
  69. * @return int
  70. */
  71. public function getMtime()
  72. {
  73. return $this->entry->getMTime()->getTimestamp();
  74. }
  75. /**
  76. * @return int|null
  77. */
  78. public function getCtime()
  79. {
  80. $ctime = $this->entry->getCTime();
  81. return $ctime === null ? null : $ctime->getTimestamp();
  82. }
  83. /**
  84. * @return int|null
  85. */
  86. public function getAtime()
  87. {
  88. $atime = $this->entry->getATime();
  89. return $atime === null ? null : $atime->getTimestamp();
  90. }
  91. /**
  92. * @return string
  93. */
  94. public function getAttributes()
  95. {
  96. $externalAttributes = $this->entry->getExternalAttributes();
  97. if ($this->entry->getCreatedOS() === ZipPlatform::OS_UNIX) {
  98. $permission = (($externalAttributes >> 16) & 0xFFFF);
  99. return FileAttribUtil::getUnixMode($permission);
  100. }
  101. return FileAttribUtil::getDosMode($externalAttributes);
  102. }
  103. /**
  104. * @return bool
  105. */
  106. public function isEncrypted()
  107. {
  108. return $this->entry->isEncrypted();
  109. }
  110. /**
  111. * @return string|null
  112. */
  113. public function getComment()
  114. {
  115. return $this->entry->getComment();
  116. }
  117. /**
  118. * @return int
  119. */
  120. public function getCrc()
  121. {
  122. return $this->entry->getCrc();
  123. }
  124. /**
  125. * @return string
  126. *
  127. * @deprecated use \PhpZip\Model\ZipInfo::getMethodName()
  128. */
  129. public function getMethod()
  130. {
  131. return $this->getMethodName();
  132. }
  133. /**
  134. * @return string
  135. */
  136. public function getMethodName()
  137. {
  138. return ZipCompressionMethod::getCompressionMethodName($this->entry->getCompressionMethod());
  139. }
  140. /**
  141. * @return string
  142. */
  143. public function getEncryptionMethodName()
  144. {
  145. return ZipEncryptionMethod::getEncryptionMethodName($this->entry->getEncryptionMethod());
  146. }
  147. /**
  148. * @return string
  149. */
  150. public function getPlatform()
  151. {
  152. return ZipPlatform::getPlatformName($this->entry->getExtractedOS());
  153. }
  154. /**
  155. * @return int
  156. */
  157. public function getVersion()
  158. {
  159. return $this->entry->getExtractVersion();
  160. }
  161. /**
  162. * @return int|null
  163. */
  164. public function getEncryptionMethod()
  165. {
  166. $encryptionMethod = $this->entry->getEncryptionMethod();
  167. return $encryptionMethod === ZipEncryptionMethod::NONE ? null : $encryptionMethod;
  168. }
  169. /**
  170. * @return int|null
  171. */
  172. public function getCompressionLevel()
  173. {
  174. return $this->entry->getCompressionLevel();
  175. }
  176. /**
  177. * @return int
  178. */
  179. public function getCompressionMethod()
  180. {
  181. return $this->entry->getCompressionMethod();
  182. }
  183. /**
  184. * @return array
  185. */
  186. public function toArray()
  187. {
  188. return [
  189. 'name' => $this->getName(),
  190. 'folder' => $this->isFolder(),
  191. 'size' => $this->getSize(),
  192. 'compressed_size' => $this->getCompressedSize(),
  193. 'modified' => $this->getMtime(),
  194. 'created' => $this->getCtime(),
  195. 'accessed' => $this->getAtime(),
  196. 'attributes' => $this->getAttributes(),
  197. 'encrypted' => $this->isEncrypted(),
  198. 'encryption_method' => $this->getEncryptionMethod(),
  199. 'encryption_method_name' => $this->getEncryptionMethodName(),
  200. 'comment' => $this->getComment(),
  201. 'crc' => $this->getCrc(),
  202. 'method_name' => $this->getMethodName(),
  203. 'compression_method' => $this->getCompressionMethod(),
  204. 'platform' => $this->getPlatform(),
  205. 'version' => $this->getVersion(),
  206. ];
  207. }
  208. /**
  209. * @return string
  210. */
  211. public function __toString()
  212. {
  213. $ctime = $this->entry->getCTime();
  214. $atime = $this->entry->getATime();
  215. $comment = $this->getComment();
  216. return __CLASS__ . ' {'
  217. . 'Name="' . $this->getName() . '", '
  218. . ($this->isFolder() ? 'Folder, ' : '')
  219. . 'Size="' . FilesUtil::humanSize($this->getSize()) . '"'
  220. . ', Compressed size="' . FilesUtil::humanSize($this->getCompressedSize()) . '"'
  221. . ', Modified time="' . $this->entry->getMTime()->format(\DATE_W3C) . '", '
  222. . ($ctime !== null ? 'Created time="' . $ctime->format(\DATE_W3C) . '", ' : '')
  223. . ($atime !== null ? 'Accessed time="' . $atime->format(\DATE_W3C) . '", ' : '')
  224. . ($this->isEncrypted() ? 'Encrypted, ' : '')
  225. . ($comment !== null ? 'Comment="' . $comment . '", ' : '')
  226. . (!empty($this->crc) ? 'Crc=0x' . dechex($this->crc) . ', ' : '')
  227. . 'Method name="' . $this->getMethodName() . '", '
  228. . 'Attributes="' . $this->getAttributes() . '", '
  229. . 'Platform="' . $this->getPlatform() . '", '
  230. . 'Version=' . $this->getVersion()
  231. . '}';
  232. }
  233. }