ZipFileWithBeforeSave.php 721 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace PhpZip\Tests\Internal\CustomZip;
  3. use PhpZip\Model\Extra\Fields\NewUnixExtraField;
  4. use PhpZip\Model\Extra\Fields\NtfsExtraField;
  5. use PhpZip\ZipFile;
  6. /**
  7. * Class ZipFileWithBeforeSave.
  8. */
  9. class ZipFileWithBeforeSave extends ZipFile
  10. {
  11. /**
  12. * Event before save or output.
  13. */
  14. protected function onBeforeSave()
  15. {
  16. $now = new \DateTimeImmutable();
  17. $ntfsTimeExtra = NtfsExtraField::create($now, $now->modify('-1 day'), $now->modify('-10 day'));
  18. $unixExtra = new NewUnixExtraField();
  19. foreach ($this->zipContainer->getEntries() as $entry) {
  20. $entry->addExtraField($ntfsTimeExtra);
  21. $entry->addExtraField($unixExtra);
  22. }
  23. }
  24. }