ZipEntry.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  1. <?php
  2. /** @noinspection PhpUsageOfSilenceOperatorInspection */
  3. namespace PhpZip\Model;
  4. use PhpZip\Constants\DosAttrs;
  5. use PhpZip\Constants\DosCodePage;
  6. use PhpZip\Constants\GeneralPurposeBitFlag;
  7. use PhpZip\Constants\UnixStat;
  8. use PhpZip\Constants\ZipCompressionLevel;
  9. use PhpZip\Constants\ZipCompressionMethod;
  10. use PhpZip\Constants\ZipConstants;
  11. use PhpZip\Constants\ZipEncryptionMethod;
  12. use PhpZip\Constants\ZipPlatform;
  13. use PhpZip\Constants\ZipVersion;
  14. use PhpZip\Exception\InvalidArgumentException;
  15. use PhpZip\Exception\RuntimeException;
  16. use PhpZip\Exception\ZipUnsupportMethodException;
  17. use PhpZip\Model\Extra\ExtraFieldsCollection;
  18. use PhpZip\Model\Extra\Fields\AsiExtraField;
  19. use PhpZip\Model\Extra\Fields\ExtendedTimestampExtraField;
  20. use PhpZip\Model\Extra\Fields\NtfsExtraField;
  21. use PhpZip\Model\Extra\Fields\OldUnixExtraField;
  22. use PhpZip\Model\Extra\Fields\UnicodePathExtraField;
  23. use PhpZip\Model\Extra\Fields\WinZipAesExtraField;
  24. use PhpZip\Model\Extra\ZipExtraField;
  25. use PhpZip\Util\DateTimeConverter;
  26. use PhpZip\Util\StringUtil;
  27. /**
  28. * ZIP file entry.
  29. *
  30. * @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT .ZIP File Format Specification
  31. *
  32. * @author Ne-Lexa alexey@nelexa.ru
  33. * @license MIT
  34. */
  35. class ZipEntry
  36. {
  37. /** @var int the unknown value for numeric properties */
  38. const UNKNOWN = -1;
  39. /**
  40. * @var int DOS platform
  41. *
  42. * @deprecated Use {@see ZipPlatform::OS_DOS}
  43. */
  44. const PLATFORM_FAT = ZipPlatform::OS_DOS;
  45. /**
  46. * @var int Unix platform
  47. *
  48. * @deprecated Use {@see ZipPlatform::OS_UNIX}
  49. */
  50. const PLATFORM_UNIX = ZipPlatform::OS_UNIX;
  51. /**
  52. * @var int MacOS platform
  53. *
  54. * @deprecated Use {@see ZipPlatform::OS_MAC_OSX}
  55. */
  56. const PLATFORM_OS_X = ZipPlatform::OS_MAC_OSX;
  57. /**
  58. * Pseudo compression method for WinZip AES encrypted entries.
  59. * Require php extension openssl or mcrypt.
  60. *
  61. * @deprecated Use {@see ZipCompressionMethod::WINZIP_AES}
  62. */
  63. const METHOD_WINZIP_AES = ZipCompressionMethod::WINZIP_AES;
  64. /** @var string Entry name (filename in archive) */
  65. private $name;
  66. /** @var bool Is directory */
  67. private $isDirectory;
  68. /** @var ZipData|null Zip entry contents */
  69. private $data;
  70. /** @var int Made by platform */
  71. private $createdOS = self::UNKNOWN;
  72. /** @var int Extracted by platform */
  73. private $extractedOS = self::UNKNOWN;
  74. /** @var int Software version */
  75. private $softwareVersion = self::UNKNOWN;
  76. /** @var int Version needed to extract */
  77. private $extractVersion = self::UNKNOWN;
  78. /** @var int Compression method */
  79. private $compressionMethod = self::UNKNOWN;
  80. /** @var int General purpose bit flags */
  81. private $generalPurposeBitFlags = 0;
  82. /** @var int Dos time */
  83. private $dosTime = self::UNKNOWN;
  84. /** @var int Crc32 */
  85. private $crc = self::UNKNOWN;
  86. /** @var int Compressed size */
  87. private $compressedSize = self::UNKNOWN;
  88. /** @var int Uncompressed size */
  89. private $uncompressedSize = self::UNKNOWN;
  90. /** @var int Internal attributes */
  91. private $internalAttributes = 0;
  92. /** @var int External attributes */
  93. private $externalAttributes = 0;
  94. /** @var int relative Offset Of Local File Header */
  95. private $localHeaderOffset = 0;
  96. /**
  97. * Collections of Extra Fields in Central Directory.
  98. * Keys from Header ID [int] and value Extra Field [ExtraField].
  99. *
  100. * @var ExtraFieldsCollection
  101. */
  102. protected $cdExtraFields;
  103. /**
  104. * Collections of Extra Fields int local header.
  105. * Keys from Header ID [int] and value Extra Field [ExtraField].
  106. *
  107. * @var ExtraFieldsCollection
  108. */
  109. protected $localExtraFields;
  110. /** @var string|null comment field */
  111. private $comment;
  112. /** @var string|null entry password for read or write encryption data */
  113. private $password;
  114. /** @var int encryption method */
  115. private $encryptionMethod = ZipEncryptionMethod::NONE;
  116. /** @var int */
  117. private $compressionLevel = ZipCompressionLevel::NORMAL;
  118. /** @var string|null */
  119. private $charset;
  120. /**
  121. * ZipEntry constructor.
  122. *
  123. * @param string $name Entry name
  124. * @param string|null $charset DOS charset
  125. */
  126. public function __construct($name, $charset = null)
  127. {
  128. $this->setName($name, $charset);
  129. $this->cdExtraFields = new ExtraFieldsCollection();
  130. $this->localExtraFields = new ExtraFieldsCollection();
  131. }
  132. /**
  133. * This method only internal use.
  134. *
  135. * @param string $name
  136. * @param int $createdOS
  137. * @param int $extractedOS
  138. * @param int $softwareVersion
  139. * @param int $extractVersion
  140. * @param int $compressionMethod
  141. * @param int $gpbf
  142. * @param int $dosTime
  143. * @param int $crc
  144. * @param int $compressedSize
  145. * @param int $uncompressedSize
  146. * @param int $internalAttributes
  147. * @param int $externalAttributes
  148. * @param int $offsetLocalHeader
  149. * @param string|null $comment
  150. * @param string|null $charset
  151. *
  152. * @return ZipEntry
  153. *
  154. * @internal
  155. *
  156. * @noinspection PhpTooManyParametersInspection
  157. */
  158. public static function create(
  159. $name,
  160. $createdOS,
  161. $extractedOS,
  162. $softwareVersion,
  163. $extractVersion,
  164. $compressionMethod,
  165. $gpbf,
  166. $dosTime,
  167. $crc,
  168. $compressedSize,
  169. $uncompressedSize,
  170. $internalAttributes,
  171. $externalAttributes,
  172. $offsetLocalHeader,
  173. $comment,
  174. $charset
  175. ) {
  176. $entry = new self($name);
  177. $entry->createdOS = (int) $createdOS;
  178. $entry->extractedOS = (int) $extractedOS;
  179. $entry->softwareVersion = (int) $softwareVersion;
  180. $entry->extractVersion = (int) $extractVersion;
  181. $entry->compressionMethod = (int) $compressionMethod;
  182. $entry->generalPurposeBitFlags = (int) $gpbf;
  183. $entry->dosTime = (int) $dosTime;
  184. $entry->crc = (int) $crc;
  185. $entry->compressedSize = (int) $compressedSize;
  186. $entry->uncompressedSize = (int) $uncompressedSize;
  187. $entry->internalAttributes = (int) $internalAttributes;
  188. $entry->externalAttributes = (int) $externalAttributes;
  189. $entry->localHeaderOffset = (int) $offsetLocalHeader;
  190. $entry->setComment($comment);
  191. $entry->setCharset($charset);
  192. $entry->updateCompressionLevel();
  193. return $entry;
  194. }
  195. /**
  196. * Set entry name.
  197. *
  198. * @param string $name New entry name
  199. * @param string|null $charset
  200. *
  201. * @return ZipEntry
  202. */
  203. private function setName($name, $charset = null)
  204. {
  205. if ($name === null) {
  206. throw new InvalidArgumentException('zip entry name is null');
  207. }
  208. $name = ltrim((string) $name, '\\/');
  209. if ($name === '') {
  210. throw new InvalidArgumentException('Empty zip entry name');
  211. }
  212. $name = (string) $name;
  213. $length = \strlen($name);
  214. if ($length > 0xffff) {
  215. throw new InvalidArgumentException('Illegal zip entry name parameter');
  216. }
  217. $this->setCharset($charset);
  218. if ($this->charset === null && !StringUtil::isASCII($name)) {
  219. $this->enableUtf8Name(true);
  220. }
  221. $this->name = $name;
  222. $this->isDirectory = ($length = \strlen($name)) >= 1 && $name[$length - 1] === '/';
  223. $this->externalAttributes = $this->isDirectory ? DosAttrs::DOS_DIRECTORY : DosAttrs::DOS_ARCHIVE;
  224. if ($this->extractVersion !== self::UNKNOWN) {
  225. $this->extractVersion = max(
  226. $this->extractVersion,
  227. $this->isDirectory ?
  228. ZipVersion::v20_DEFLATED_FOLDER_ZIPCRYPTO :
  229. ZipVersion::v10_DEFAULT_MIN
  230. );
  231. }
  232. return $this;
  233. }
  234. /**
  235. * @param string|null $charset
  236. *
  237. * @return ZipEntry
  238. *
  239. * @see DosCodePage::getCodePages()
  240. */
  241. public function setCharset($charset = null)
  242. {
  243. if ($charset !== null && $charset === '') {
  244. throw new InvalidArgumentException('Empty charset');
  245. }
  246. $this->charset = $charset;
  247. return $this;
  248. }
  249. /**
  250. * @return string|null
  251. */
  252. public function getCharset()
  253. {
  254. return $this->charset;
  255. }
  256. /**
  257. * @param string $newName New entry name
  258. *
  259. * @return ZipEntry new {@see ZipEntry} object with new name
  260. *
  261. * @internal
  262. */
  263. public function rename($newName)
  264. {
  265. $newEntry = clone $this;
  266. $newEntry->setName($newName);
  267. $newEntry->removeExtraField(UnicodePathExtraField::HEADER_ID);
  268. return $newEntry;
  269. }
  270. /**
  271. * Returns the ZIP entry name.
  272. *
  273. * @return string
  274. */
  275. public function getName()
  276. {
  277. return $this->name;
  278. }
  279. /**
  280. * @return ZipData|null
  281. *
  282. * @internal
  283. */
  284. public function getData()
  285. {
  286. return $this->data;
  287. }
  288. /**
  289. * @param ZipData|null $data
  290. *
  291. * @internal
  292. */
  293. public function setData($data)
  294. {
  295. $this->data = $data;
  296. }
  297. /**
  298. * @return int Get platform
  299. *
  300. * @deprecated Use {@see ZipEntry::getCreatedOS()}
  301. */
  302. public function getPlatform()
  303. {
  304. @trigger_error(__METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::getCreatedOS()', \E_USER_DEPRECATED);
  305. return $this->getCreatedOS();
  306. }
  307. /**
  308. * @param int $platform
  309. *
  310. * @return ZipEntry
  311. *
  312. * @deprecated Use {@see ZipEntry::setCreatedOS()}
  313. */
  314. public function setPlatform($platform)
  315. {
  316. @trigger_error(__METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::setCreatedOS()', \E_USER_DEPRECATED);
  317. return $this->setCreatedOS($platform);
  318. }
  319. /**
  320. * @return int platform
  321. */
  322. public function getCreatedOS()
  323. {
  324. return $this->createdOS;
  325. }
  326. /**
  327. * Set platform.
  328. *
  329. * @param int $platform
  330. *
  331. * @return ZipEntry
  332. */
  333. public function setCreatedOS($platform)
  334. {
  335. $platform = (int) $platform;
  336. if ($platform < 0x00 || $platform > 0xff) {
  337. throw new InvalidArgumentException('Platform out of range');
  338. }
  339. $this->createdOS = $platform;
  340. return $this;
  341. }
  342. /**
  343. * @return int
  344. */
  345. public function getExtractedOS()
  346. {
  347. return $this->extractedOS;
  348. }
  349. /**
  350. * Set extracted OS.
  351. *
  352. * @param int $platform
  353. *
  354. * @return ZipEntry
  355. */
  356. public function setExtractedOS($platform)
  357. {
  358. $platform = (int) $platform;
  359. if ($platform < 0x00 || $platform > 0xff) {
  360. throw new InvalidArgumentException('Platform out of range');
  361. }
  362. $this->extractedOS = $platform;
  363. return $this;
  364. }
  365. /**
  366. * @return int
  367. */
  368. public function getSoftwareVersion()
  369. {
  370. if ($this->softwareVersion === self::UNKNOWN) {
  371. return $this->getExtractVersion();
  372. }
  373. return $this->softwareVersion;
  374. }
  375. /**
  376. * @param int $softwareVersion
  377. *
  378. * @return ZipEntry
  379. */
  380. public function setSoftwareVersion($softwareVersion)
  381. {
  382. $this->softwareVersion = (int) $softwareVersion;
  383. return $this;
  384. }
  385. /**
  386. * Version needed to extract.
  387. *
  388. * @return int
  389. *
  390. * @deprecated Use {@see ZipEntry::getExtractVersion()}
  391. */
  392. public function getVersionNeededToExtract()
  393. {
  394. @trigger_error(__METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::getExtractVersion()', \E_USER_DEPRECATED);
  395. return $this->getExtractVersion();
  396. }
  397. /**
  398. * Version needed to extract.
  399. *
  400. * @return int
  401. */
  402. public function getExtractVersion()
  403. {
  404. if ($this->extractVersion === self::UNKNOWN) {
  405. if (ZipEncryptionMethod::isWinZipAesMethod($this->encryptionMethod)) {
  406. return ZipVersion::v51_ENCR_AES_RC2_CORRECT;
  407. }
  408. if ($this->compressionMethod === ZipCompressionMethod::BZIP2) {
  409. return ZipVersion::v46_BZIP2;
  410. }
  411. if ($this->isZip64ExtensionsRequired()) {
  412. return ZipVersion::v45_ZIP64_EXT;
  413. }
  414. if (
  415. $this->compressionMethod === ZipCompressionMethod::DEFLATED ||
  416. $this->isDirectory ||
  417. $this->encryptionMethod === ZipEncryptionMethod::PKWARE
  418. ) {
  419. return ZipVersion::v20_DEFLATED_FOLDER_ZIPCRYPTO;
  420. }
  421. return ZipVersion::v10_DEFAULT_MIN;
  422. }
  423. return $this->extractVersion;
  424. }
  425. /**
  426. * Set version needed to extract.
  427. *
  428. * @param int $version
  429. *
  430. * @return ZipEntry
  431. *
  432. * @deprecated Use {@see ZipEntry::setExtractVersion()}
  433. */
  434. public function setVersionNeededToExtract($version)
  435. {
  436. @trigger_error(__METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::setExtractVersion()', \E_USER_DEPRECATED);
  437. return $this->setExtractVersion($version);
  438. }
  439. /**
  440. * Set version needed to extract.
  441. *
  442. * @param int $version
  443. *
  444. * @return ZipEntry
  445. */
  446. public function setExtractVersion($version)
  447. {
  448. $this->extractVersion = max(ZipVersion::v10_DEFAULT_MIN, (int) $version);
  449. return $this;
  450. }
  451. /**
  452. * Returns the compressed size of this entry.
  453. *
  454. * @return int
  455. */
  456. public function getCompressedSize()
  457. {
  458. return $this->compressedSize;
  459. }
  460. /**
  461. * Sets the compressed size of this entry.
  462. *
  463. * @param int $compressedSize the Compressed Size
  464. *
  465. * @return ZipEntry
  466. *
  467. * @internal
  468. */
  469. public function setCompressedSize($compressedSize)
  470. {
  471. $compressedSize = (int) $compressedSize;
  472. if ($compressedSize < self::UNKNOWN) {
  473. throw new InvalidArgumentException('Compressed size < ' . self::UNKNOWN);
  474. }
  475. $this->compressedSize = $compressedSize;
  476. return $this;
  477. }
  478. /**
  479. * Returns the uncompressed size of this entry.
  480. *
  481. * @return int
  482. *
  483. * @deprecated Use {@see ZipEntry::getUncompressedSize()}
  484. */
  485. public function getSize()
  486. {
  487. @trigger_error(__METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::getUncompressedSize()', \E_USER_DEPRECATED);
  488. return $this->getUncompressedSize();
  489. }
  490. /**
  491. * Sets the uncompressed size of this entry.
  492. *
  493. * @param int $size the (Uncompressed) Size
  494. *
  495. * @return ZipEntry
  496. *
  497. * @deprecated Use {@see ZipEntry::setUncompressedSize()}
  498. *
  499. * @internal
  500. */
  501. public function setSize($size)
  502. {
  503. @trigger_error(__METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::setUncompressedSize()', \E_USER_DEPRECATED);
  504. return $this->setUncompressedSize($size);
  505. }
  506. /**
  507. * Returns the uncompressed size of this entry.
  508. *
  509. * @return int
  510. */
  511. public function getUncompressedSize()
  512. {
  513. return $this->uncompressedSize;
  514. }
  515. /**
  516. * Sets the uncompressed size of this entry.
  517. *
  518. * @param int $uncompressedSize the (Uncompressed) Size
  519. *
  520. * @return ZipEntry
  521. *
  522. * @internal
  523. */
  524. public function setUncompressedSize($uncompressedSize)
  525. {
  526. $uncompressedSize = (int) $uncompressedSize;
  527. if ($uncompressedSize < self::UNKNOWN) {
  528. throw new InvalidArgumentException('Uncompressed size < ' . self::UNKNOWN);
  529. }
  530. $this->uncompressedSize = $uncompressedSize;
  531. return $this;
  532. }
  533. /**
  534. * Return relative Offset Of Local File Header.
  535. *
  536. * @return int
  537. */
  538. public function getLocalHeaderOffset()
  539. {
  540. return $this->localHeaderOffset;
  541. }
  542. /**
  543. * @param int $localHeaderOffset
  544. *
  545. * @return ZipEntry
  546. *
  547. * @internal
  548. */
  549. public function setLocalHeaderOffset($localHeaderOffset)
  550. {
  551. $localHeaderOffset = (int) $localHeaderOffset;
  552. if ($localHeaderOffset < 0) {
  553. throw new InvalidArgumentException('Negative $localHeaderOffset');
  554. }
  555. $this->localHeaderOffset = $localHeaderOffset;
  556. return $this;
  557. }
  558. /**
  559. * Return relative Offset Of Local File Header.
  560. *
  561. * @return int
  562. *
  563. * @deprecated Use {@see ZipEntry::getLocalHeaderOffset()}
  564. */
  565. public function getOffset()
  566. {
  567. @trigger_error(
  568. __METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::getLocalHeaderOffset()',
  569. \E_USER_DEPRECATED
  570. );
  571. return $this->getLocalHeaderOffset();
  572. }
  573. /**
  574. * @param int $offset
  575. *
  576. * @return ZipEntry
  577. *
  578. * @deprecated Use {@see ZipEntry::setLocalHeaderOffset()}
  579. *
  580. * @internal
  581. */
  582. public function setOffset($offset)
  583. {
  584. @trigger_error(
  585. __METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::setLocalHeaderOffset()',
  586. \E_USER_DEPRECATED
  587. );
  588. return $this->setLocalHeaderOffset($offset);
  589. }
  590. /**
  591. * Returns the General Purpose Bit Flags.
  592. *
  593. * @return int
  594. */
  595. public function getGeneralPurposeBitFlags()
  596. {
  597. return $this->generalPurposeBitFlags;
  598. }
  599. /**
  600. * Sets the General Purpose Bit Flags.
  601. *
  602. * @param int $gpbf general purpose bit flags
  603. *
  604. * @return ZipEntry
  605. *
  606. * @internal
  607. */
  608. public function setGeneralPurposeBitFlags($gpbf)
  609. {
  610. $gpbf = (int) $gpbf;
  611. if ($gpbf < 0x0000 || $gpbf > 0xffff) {
  612. throw new InvalidArgumentException('general purpose bit flags out of range');
  613. }
  614. $this->generalPurposeBitFlags = $gpbf;
  615. $this->updateCompressionLevel();
  616. return $this;
  617. }
  618. private function updateCompressionLevel()
  619. {
  620. if ($this->compressionMethod === ZipCompressionMethod::DEFLATED) {
  621. $bit1 = $this->isSetGeneralBitFlag(GeneralPurposeBitFlag::COMPRESSION_FLAG1);
  622. $bit2 = $this->isSetGeneralBitFlag(GeneralPurposeBitFlag::COMPRESSION_FLAG2);
  623. if ($bit1 && !$bit2) {
  624. $this->compressionLevel = ZipCompressionLevel::MAXIMUM;
  625. } elseif (!$bit1 && $bit2) {
  626. $this->compressionLevel = ZipCompressionLevel::FAST;
  627. } elseif ($bit1 && $bit2) {
  628. $this->compressionLevel = ZipCompressionLevel::SUPER_FAST;
  629. } else {
  630. $this->compressionLevel = ZipCompressionLevel::NORMAL;
  631. }
  632. }
  633. }
  634. /**
  635. * @param int $mask
  636. * @param bool $enable
  637. *
  638. * @return ZipEntry
  639. */
  640. private function setGeneralBitFlag($mask, $enable)
  641. {
  642. if ($enable) {
  643. $this->generalPurposeBitFlags |= $mask;
  644. } else {
  645. $this->generalPurposeBitFlags &= ~$mask;
  646. }
  647. return $this;
  648. }
  649. /**
  650. * @param int $mask
  651. *
  652. * @return bool
  653. */
  654. private function isSetGeneralBitFlag($mask)
  655. {
  656. return ($this->generalPurposeBitFlags & $mask) === $mask;
  657. }
  658. /**
  659. * @return bool
  660. */
  661. public function isDataDescriptorEnabled()
  662. {
  663. return $this->isSetGeneralBitFlag(GeneralPurposeBitFlag::DATA_DESCRIPTOR);
  664. }
  665. /**
  666. * Enabling or disabling the use of the Data Descriptor block.
  667. *
  668. * @param bool $enabled
  669. */
  670. public function enableDataDescriptor($enabled = true)
  671. {
  672. $this->setGeneralBitFlag(GeneralPurposeBitFlag::DATA_DESCRIPTOR, (bool) $enabled);
  673. }
  674. /**
  675. * @param bool $enabled
  676. */
  677. public function enableUtf8Name($enabled)
  678. {
  679. $this->setGeneralBitFlag(GeneralPurposeBitFlag::UTF8, (bool) $enabled);
  680. }
  681. /**
  682. * @return bool
  683. */
  684. public function isUtf8Flag()
  685. {
  686. return $this->isSetGeneralBitFlag(GeneralPurposeBitFlag::UTF8);
  687. }
  688. /**
  689. * Returns true if and only if this ZIP entry is encrypted.
  690. *
  691. * @return bool
  692. */
  693. public function isEncrypted()
  694. {
  695. return $this->isSetGeneralBitFlag(GeneralPurposeBitFlag::ENCRYPTION);
  696. }
  697. /**
  698. * @return bool
  699. */
  700. public function isStrongEncryption()
  701. {
  702. return $this->isSetGeneralBitFlag(GeneralPurposeBitFlag::STRONG_ENCRYPTION);
  703. }
  704. /**
  705. * Sets the encryption property to false and removes any other
  706. * encryption artifacts.
  707. *
  708. * @return ZipEntry
  709. */
  710. public function disableEncryption()
  711. {
  712. $this->setEncrypted(false);
  713. $this->removeExtraField(WinZipAesExtraField::HEADER_ID);
  714. $this->encryptionMethod = ZipEncryptionMethod::NONE;
  715. $this->password = null;
  716. $this->extractVersion = self::UNKNOWN;
  717. return $this;
  718. }
  719. /**
  720. * Sets the encryption flag for this ZIP entry.
  721. *
  722. * @param bool $encrypted
  723. *
  724. * @return ZipEntry
  725. */
  726. private function setEncrypted($encrypted)
  727. {
  728. $encrypted = (bool) $encrypted;
  729. $this->setGeneralBitFlag(GeneralPurposeBitFlag::ENCRYPTION, $encrypted);
  730. return $this;
  731. }
  732. /**
  733. * Returns the compression method for this entry.
  734. *
  735. * @return int
  736. *
  737. * @deprecated Use {@see ZipEntry::getCompressionMethod()}
  738. */
  739. public function getMethod()
  740. {
  741. @trigger_error(
  742. __METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::getCompressionMethod()',
  743. \E_USER_DEPRECATED
  744. );
  745. return $this->getCompressionMethod();
  746. }
  747. /**
  748. * Returns the compression method for this entry.
  749. *
  750. * @return int
  751. */
  752. public function getCompressionMethod()
  753. {
  754. return $this->compressionMethod;
  755. }
  756. /**
  757. * Sets the compression method for this entry.
  758. *
  759. * @param int $method
  760. *
  761. * @throws ZipUnsupportMethodException
  762. *
  763. * @return ZipEntry
  764. *
  765. * @deprecated Use {@see ZipEntry::setCompressionMethod()}
  766. */
  767. public function setMethod($method)
  768. {
  769. @trigger_error(
  770. __METHOD__ . ' is deprecated. Use ' . __CLASS__ . '::setCompressionMethod()',
  771. \E_USER_DEPRECATED
  772. );
  773. return $this->setCompressionMethod($method);
  774. }
  775. /**
  776. * Sets the compression method for this entry.
  777. *
  778. * @param int $compressionMethod
  779. *
  780. * @throws ZipUnsupportMethodException
  781. *
  782. * @return ZipEntry
  783. *
  784. * @see ZipCompressionMethod::STORED
  785. * @see ZipCompressionMethod::DEFLATED
  786. * @see ZipCompressionMethod::BZIP2
  787. */
  788. public function setCompressionMethod($compressionMethod)
  789. {
  790. $compressionMethod = (int) $compressionMethod;
  791. if ($compressionMethod < 0x0000 || $compressionMethod > 0xffff) {
  792. throw new InvalidArgumentException('method out of range: ' . $compressionMethod);
  793. }
  794. ZipCompressionMethod::checkSupport($compressionMethod);
  795. $this->compressionMethod = $compressionMethod;
  796. $this->updateCompressionLevel();
  797. $this->extractVersion = self::UNKNOWN;
  798. return $this;
  799. }
  800. /**
  801. * Get Unix Timestamp.
  802. *
  803. * @return int
  804. */
  805. public function getTime()
  806. {
  807. if ($this->getDosTime() === self::UNKNOWN) {
  808. return self::UNKNOWN;
  809. }
  810. return DateTimeConverter::msDosToUnix($this->getDosTime());
  811. }
  812. /**
  813. * Get Dos Time.
  814. *
  815. * @return int
  816. */
  817. public function getDosTime()
  818. {
  819. return $this->dosTime;
  820. }
  821. /**
  822. * Set Dos Time.
  823. *
  824. * @param int $dosTime
  825. *
  826. * @return ZipEntry
  827. */
  828. public function setDosTime($dosTime)
  829. {
  830. $dosTime = (int) $dosTime;
  831. if ($dosTime < 0x00000000 || $dosTime > 0xffffffff) {
  832. throw new InvalidArgumentException('DosTime out of range');
  833. }
  834. $this->dosTime = $dosTime;
  835. return $this;
  836. }
  837. /**
  838. * Set time from unix timestamp.
  839. *
  840. * @param int $unixTimestamp
  841. *
  842. * @return ZipEntry
  843. */
  844. public function setTime($unixTimestamp)
  845. {
  846. if ($unixTimestamp !== self::UNKNOWN) {
  847. $this->setDosTime(DateTimeConverter::unixToMsDos($unixTimestamp));
  848. } else {
  849. $this->dosTime = 0;
  850. }
  851. return $this;
  852. }
  853. /**
  854. * Returns the external file attributes.
  855. *
  856. * @return int the external file attributes
  857. */
  858. public function getExternalAttributes()
  859. {
  860. return $this->externalAttributes;
  861. }
  862. /**
  863. * Sets the external file attributes.
  864. *
  865. * @param int $externalAttributes the external file attributes
  866. *
  867. * @return ZipEntry
  868. */
  869. public function setExternalAttributes($externalAttributes)
  870. {
  871. $this->externalAttributes = (int) $externalAttributes;
  872. if ($externalAttributes < 0x00000000 || $externalAttributes > 0xffffffff) {
  873. throw new InvalidArgumentException('external attributes out of range: ' . $externalAttributes);
  874. }
  875. $this->externalAttributes = $externalAttributes;
  876. return $this;
  877. }
  878. /**
  879. * Returns the internal file attributes.
  880. *
  881. * @return int the internal file attributes
  882. */
  883. public function getInternalAttributes()
  884. {
  885. return $this->internalAttributes;
  886. }
  887. /**
  888. * Sets the internal file attributes.
  889. *
  890. * @param int $internalAttributes the internal file attributes
  891. *
  892. * @return ZipEntry
  893. */
  894. public function setInternalAttributes($internalAttributes)
  895. {
  896. $internalAttributes = (int) $internalAttributes;
  897. if ($internalAttributes < 0x0000 || $internalAttributes > 0xffff) {
  898. throw new InvalidArgumentException('internal attributes out of range');
  899. }
  900. $this->internalAttributes = $internalAttributes;
  901. return $this;
  902. }
  903. /**
  904. * Returns true if and only if this ZIP entry represents a directory entry
  905. * (i.e. end with '/').
  906. *
  907. * @return bool
  908. */
  909. final public function isDirectory()
  910. {
  911. return $this->isDirectory;
  912. }
  913. /**
  914. * @return ExtraFieldsCollection
  915. */
  916. public function getCdExtraFields()
  917. {
  918. return $this->cdExtraFields;
  919. }
  920. /**
  921. * @param int $headerId
  922. *
  923. * @return ZipExtraField|null
  924. */
  925. public function getCdExtraField($headerId)
  926. {
  927. return $this->cdExtraFields->get((int) $headerId);
  928. }
  929. /**
  930. * @param ExtraFieldsCollection $cdExtraFields
  931. *
  932. * @return ZipEntry
  933. */
  934. public function setCdExtraFields(ExtraFieldsCollection $cdExtraFields)
  935. {
  936. $this->cdExtraFields = $cdExtraFields;
  937. return $this;
  938. }
  939. /**
  940. * @return ExtraFieldsCollection
  941. */
  942. public function getLocalExtraFields()
  943. {
  944. return $this->localExtraFields;
  945. }
  946. /**
  947. * @param int $headerId
  948. *
  949. * @return ZipExtraField|null
  950. */
  951. public function getLocalExtraField($headerId)
  952. {
  953. return $this->localExtraFields[(int) $headerId];
  954. }
  955. /**
  956. * @param ExtraFieldsCollection $localExtraFields
  957. *
  958. * @return ZipEntry
  959. */
  960. public function setLocalExtraFields(ExtraFieldsCollection $localExtraFields)
  961. {
  962. $this->localExtraFields = $localExtraFields;
  963. return $this;
  964. }
  965. /**
  966. * @param int $headerId
  967. *
  968. * @return ZipExtraField|null
  969. */
  970. public function getExtraField($headerId)
  971. {
  972. $headerId = (int) $headerId;
  973. $local = $this->getLocalExtraField($headerId);
  974. if ($local === null) {
  975. return $this->getCdExtraField($headerId);
  976. }
  977. return $local;
  978. }
  979. /**
  980. * @param int $headerId
  981. *
  982. * @return bool
  983. */
  984. public function hasExtraField($headerId)
  985. {
  986. $headerId = (int) $headerId;
  987. return
  988. isset($this->localExtraFields[$headerId]) ||
  989. isset($this->cdExtraFields[$headerId]);
  990. }
  991. /**
  992. * @param int $headerId
  993. */
  994. public function removeExtraField($headerId)
  995. {
  996. $headerId = (int) $headerId;
  997. $this->cdExtraFields->remove($headerId);
  998. $this->localExtraFields->remove($headerId);
  999. }
  1000. /**
  1001. * @param ZipExtraField $zipExtraField
  1002. */
  1003. public function addExtraField(ZipExtraField $zipExtraField)
  1004. {
  1005. $this->addLocalExtraField($zipExtraField);
  1006. $this->addCdExtraField($zipExtraField);
  1007. }
  1008. /**
  1009. * @param ZipExtraField $zipExtraField
  1010. */
  1011. public function addLocalExtraField(ZipExtraField $zipExtraField)
  1012. {
  1013. $this->localExtraFields->add($zipExtraField);
  1014. }
  1015. /**
  1016. * @param ZipExtraField $zipExtraField
  1017. */
  1018. public function addCdExtraField(ZipExtraField $zipExtraField)
  1019. {
  1020. $this->cdExtraFields->add($zipExtraField);
  1021. }
  1022. /**
  1023. * Returns comment entry.
  1024. *
  1025. * @return string
  1026. */
  1027. public function getComment()
  1028. {
  1029. return $this->comment !== null ? $this->comment : '';
  1030. }
  1031. /**
  1032. * Set entry comment.
  1033. *
  1034. * @param string|null $comment
  1035. *
  1036. * @return ZipEntry
  1037. */
  1038. public function setComment($comment)
  1039. {
  1040. if ($comment !== null) {
  1041. $commentLength = \strlen($comment);
  1042. if ($commentLength > 0xffff) {
  1043. throw new InvalidArgumentException('Comment too long');
  1044. }
  1045. if ($this->charset === null && !StringUtil::isASCII($comment)) {
  1046. $this->enableUtf8Name(true);
  1047. }
  1048. }
  1049. $this->comment = $comment;
  1050. return $this;
  1051. }
  1052. /**
  1053. * @return bool
  1054. */
  1055. public function isDataDescriptorRequired()
  1056. {
  1057. return ($this->getCrc() | $this->getCompressedSize() | $this->getUncompressedSize()) === self::UNKNOWN;
  1058. }
  1059. /**
  1060. * Return crc32 content or 0 for WinZip AES v2.
  1061. *
  1062. * @return int
  1063. */
  1064. public function getCrc()
  1065. {
  1066. return $this->crc;
  1067. }
  1068. /**
  1069. * Set crc32 content.
  1070. *
  1071. * @param int $crc
  1072. *
  1073. * @return ZipEntry
  1074. *
  1075. * @internal
  1076. */
  1077. public function setCrc($crc)
  1078. {
  1079. $this->crc = (int) $crc;
  1080. return $this;
  1081. }
  1082. /**
  1083. * @return string|null
  1084. */
  1085. public function getPassword()
  1086. {
  1087. return $this->password;
  1088. }
  1089. /**
  1090. * Set password and encryption method from entry.
  1091. *
  1092. * @param string|null $password
  1093. * @param int|null $encryptionMethod
  1094. *
  1095. * @return ZipEntry
  1096. */
  1097. public function setPassword($password, $encryptionMethod = null)
  1098. {
  1099. if (!$this->isDirectory) {
  1100. if ($password === null || $password === '') {
  1101. $this->password = null;
  1102. $this->disableEncryption();
  1103. } else {
  1104. $this->password = (string) $password;
  1105. if ($encryptionMethod === null && $this->encryptionMethod === ZipEncryptionMethod::NONE) {
  1106. $encryptionMethod = ZipEncryptionMethod::WINZIP_AES_256;
  1107. }
  1108. if ($encryptionMethod !== null) {
  1109. $this->setEncryptionMethod($encryptionMethod);
  1110. }
  1111. $this->setEncrypted(true);
  1112. }
  1113. }
  1114. return $this;
  1115. }
  1116. /**
  1117. * @return int
  1118. */
  1119. public function getEncryptionMethod()
  1120. {
  1121. return $this->encryptionMethod;
  1122. }
  1123. /**
  1124. * Set encryption method.
  1125. *
  1126. * @param int|null $encryptionMethod
  1127. *
  1128. * @return ZipEntry
  1129. *
  1130. * @see ZipEncryptionMethod::NONE
  1131. * @see ZipEncryptionMethod::PKWARE
  1132. * @see ZipEncryptionMethod::WINZIP_AES_256
  1133. * @see ZipEncryptionMethod::WINZIP_AES_192
  1134. * @see ZipEncryptionMethod::WINZIP_AES_128
  1135. */
  1136. public function setEncryptionMethod($encryptionMethod)
  1137. {
  1138. if ($encryptionMethod === null) {
  1139. $encryptionMethod = ZipEncryptionMethod::NONE;
  1140. }
  1141. $encryptionMethod = (int) $encryptionMethod;
  1142. ZipEncryptionMethod::checkSupport($encryptionMethod);
  1143. $this->encryptionMethod = $encryptionMethod;
  1144. $this->setEncrypted($this->encryptionMethod !== ZipEncryptionMethod::NONE);
  1145. $this->extractVersion = self::UNKNOWN;
  1146. return $this;
  1147. }
  1148. /**
  1149. * @return int
  1150. */
  1151. public function getCompressionLevel()
  1152. {
  1153. return $this->compressionLevel;
  1154. }
  1155. /**
  1156. * @param int $compressionLevel
  1157. *
  1158. * @return ZipEntry
  1159. */
  1160. public function setCompressionLevel($compressionLevel)
  1161. {
  1162. $compressionLevel = (int) $compressionLevel;
  1163. if ($compressionLevel === self::UNKNOWN) {
  1164. $compressionLevel = ZipCompressionLevel::NORMAL;
  1165. }
  1166. if (
  1167. $compressionLevel < ZipCompressionLevel::LEVEL_MIN ||
  1168. $compressionLevel > ZipCompressionLevel::LEVEL_MAX
  1169. ) {
  1170. throw new InvalidArgumentException(
  1171. 'Invalid compression level. Minimum level ' .
  1172. ZipCompressionLevel::LEVEL_MIN . '. Maximum level ' . ZipCompressionLevel::LEVEL_MAX
  1173. );
  1174. }
  1175. $this->compressionLevel = $compressionLevel;
  1176. $this->updateGbpfCompLevel();
  1177. return $this;
  1178. }
  1179. /**
  1180. * Update general purpose bit flogs.
  1181. */
  1182. private function updateGbpfCompLevel()
  1183. {
  1184. if ($this->compressionMethod === ZipCompressionMethod::DEFLATED) {
  1185. $bit1 = false;
  1186. $bit2 = false;
  1187. switch ($this->compressionLevel) {
  1188. case ZipCompressionLevel::MAXIMUM:
  1189. $bit1 = true;
  1190. break;
  1191. case ZipCompressionLevel::FAST:
  1192. $bit2 = true;
  1193. break;
  1194. case ZipCompressionLevel::SUPER_FAST:
  1195. $bit1 = true;
  1196. $bit2 = true;
  1197. break;
  1198. // default is ZipCompressionLevel::NORMAL
  1199. }
  1200. $this->generalPurposeBitFlags |= ($bit1 ? GeneralPurposeBitFlag::COMPRESSION_FLAG1 : 0);
  1201. $this->generalPurposeBitFlags |= ($bit2 ? GeneralPurposeBitFlag::COMPRESSION_FLAG2 : 0);
  1202. }
  1203. }
  1204. /**
  1205. * Sets Unix permissions in a way that is understood by Info-Zip's
  1206. * unzip command.
  1207. *
  1208. * @param int $mode mode an int value
  1209. *
  1210. * @return ZipEntry
  1211. */
  1212. public function setUnixMode($mode)
  1213. {
  1214. $mode = (int) $mode;
  1215. $this->setExternalAttributes(
  1216. ($mode << 16)
  1217. // MS-DOS read-only attribute
  1218. | (($mode & UnixStat::UNX_IWUSR) === 0 ? DosAttrs::DOS_HIDDEN : 0)
  1219. // MS-DOS directory flag
  1220. | ($this->isDirectory() ? DosAttrs::DOS_DIRECTORY : DosAttrs::DOS_ARCHIVE)
  1221. );
  1222. $this->createdOS = ZipPlatform::OS_UNIX;
  1223. return $this;
  1224. }
  1225. /**
  1226. * Unix permission.
  1227. *
  1228. * @return int the unix permissions
  1229. */
  1230. public function getUnixMode()
  1231. {
  1232. $mode = 0;
  1233. if ($this->createdOS === ZipPlatform::OS_UNIX) {
  1234. $mode = ($this->externalAttributes >> 16) & 0xFFFF;
  1235. } elseif ($this->hasExtraField(AsiExtraField::HEADER_ID)) {
  1236. /** @var AsiExtraField $asiExtraField */
  1237. $asiExtraField = $this->getExtraField(AsiExtraField::HEADER_ID);
  1238. $mode = $asiExtraField->getMode();
  1239. }
  1240. if ($mode > 0) {
  1241. return $mode;
  1242. }
  1243. return $this->isDirectory ? 040755 : 0100644;
  1244. }
  1245. /**
  1246. * Offset MUST be considered in decision about ZIP64 format - see
  1247. * description of Data Descriptor in ZIP File Format Specification.
  1248. *
  1249. * @return bool
  1250. */
  1251. public function isZip64ExtensionsRequired()
  1252. {
  1253. return $this->compressedSize > ZipConstants::ZIP64_MAGIC
  1254. || $this->uncompressedSize > ZipConstants::ZIP64_MAGIC;
  1255. }
  1256. /**
  1257. * Returns true if this entry represents a unix symlink,
  1258. * in which case the entry's content contains the target path
  1259. * for the symlink.
  1260. *
  1261. * @return bool true if the entry represents a unix symlink,
  1262. * false otherwise
  1263. */
  1264. public function isUnixSymlink()
  1265. {
  1266. return ($this->getUnixMode() & UnixStat::UNX_IFMT) === UnixStat::UNX_IFLNK;
  1267. }
  1268. /**
  1269. * @return \DateTimeInterface
  1270. */
  1271. public function getMTime()
  1272. {
  1273. /** @var NtfsExtraField|null $ntfsExtra */
  1274. $ntfsExtra = $this->getExtraField(NtfsExtraField::HEADER_ID);
  1275. if ($ntfsExtra !== null) {
  1276. return $ntfsExtra->getModifyDateTime();
  1277. }
  1278. /** @var ExtendedTimestampExtraField|null $extendedExtra */
  1279. $extendedExtra = $this->getExtraField(ExtendedTimestampExtraField::HEADER_ID);
  1280. if ($extendedExtra !== null && ($mtime = $extendedExtra->getModifyDateTime()) !== null) {
  1281. return $mtime;
  1282. }
  1283. /** @var OldUnixExtraField|null $oldUnixExtra */
  1284. $oldUnixExtra = $this->getExtraField(OldUnixExtraField::HEADER_ID);
  1285. if ($oldUnixExtra !== null && ($mtime = $oldUnixExtra->getModifyDateTime()) !== null) {
  1286. return $mtime;
  1287. }
  1288. $timestamp = $this->getTime();
  1289. try {
  1290. return new \DateTimeImmutable('@' . $timestamp);
  1291. } catch (\Exception $e) {
  1292. throw new RuntimeException('Error create DateTime object with timestamp ' . $timestamp, 1, $e);
  1293. }
  1294. }
  1295. /**
  1296. * @return \DateTimeInterface|null
  1297. */
  1298. public function getATime()
  1299. {
  1300. /** @var NtfsExtraField|null $ntfsExtra */
  1301. $ntfsExtra = $this->getExtraField(NtfsExtraField::HEADER_ID);
  1302. if ($ntfsExtra !== null) {
  1303. return $ntfsExtra->getAccessDateTime();
  1304. }
  1305. /** @var ExtendedTimestampExtraField|null $extendedExtra */
  1306. $extendedExtra = $this->getExtraField(ExtendedTimestampExtraField::HEADER_ID);
  1307. if ($extendedExtra !== null && ($atime = $extendedExtra->getAccessDateTime()) !== null) {
  1308. return $atime;
  1309. }
  1310. /** @var OldUnixExtraField|null $oldUnixExtra */
  1311. $oldUnixExtra = $this->getExtraField(OldUnixExtraField::HEADER_ID);
  1312. if ($oldUnixExtra !== null) {
  1313. return $oldUnixExtra->getAccessDateTime();
  1314. }
  1315. return null;
  1316. }
  1317. /**
  1318. * @return \DateTimeInterface|null
  1319. */
  1320. public function getCTime()
  1321. {
  1322. /** @var NtfsExtraField|null $ntfsExtra */
  1323. $ntfsExtra = $this->getExtraField(NtfsExtraField::HEADER_ID);
  1324. if ($ntfsExtra !== null) {
  1325. return $ntfsExtra->getCreateDateTime();
  1326. }
  1327. /** @var ExtendedTimestampExtraField|null $extendedExtra */
  1328. $extendedExtra = $this->getExtraField(ExtendedTimestampExtraField::HEADER_ID);
  1329. if ($extendedExtra !== null) {
  1330. return $extendedExtra->getCreateDateTime();
  1331. }
  1332. return null;
  1333. }
  1334. public function __clone()
  1335. {
  1336. $this->cdExtraFields = clone $this->cdExtraFields;
  1337. $this->localExtraFields = clone $this->localExtraFields;
  1338. if ($this->data !== null) {
  1339. $this->data = clone $this->data;
  1340. }
  1341. }
  1342. }