ZipFileWithBeforeSave.php 948 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the nelexa/zip package.
  5. * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace PhpZip\Tests\Internal\CustomZip;
  10. use PhpZip\Model\Extra\Fields\NewUnixExtraField;
  11. use PhpZip\Model\Extra\Fields\NtfsExtraField;
  12. use PhpZip\ZipFile;
  13. class ZipFileWithBeforeSave extends ZipFile
  14. {
  15. /**
  16. * Event before save or output.
  17. */
  18. protected function onBeforeSave(): void
  19. {
  20. $now = new \DateTimeImmutable();
  21. $ntfsTimeExtra = NtfsExtraField::create($now, $now->modify('-1 day'), $now->modify('-10 day'));
  22. $unixExtra = new NewUnixExtraField();
  23. foreach ($this->zipContainer->getEntries() as $entry) {
  24. $entry->addExtraField($ntfsTimeExtra);
  25. $entry->addExtraField($unixExtra);
  26. }
  27. }
  28. }