ImmutableZipContainer.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\Model;
  10. class ImmutableZipContainer implements \Countable
  11. {
  12. /** @var ZipEntry[] */
  13. protected array $entries;
  14. /** @var string|null Archive comment */
  15. protected ?string $archiveComment;
  16. /**
  17. * @param ZipEntry[] $entries
  18. */
  19. public function __construct(array $entries, ?string $archiveComment = null)
  20. {
  21. $this->entries = $entries;
  22. $this->archiveComment = $archiveComment;
  23. }
  24. /**
  25. * @return ZipEntry[]
  26. */
  27. public function &getEntries(): array
  28. {
  29. return $this->entries;
  30. }
  31. public function getArchiveComment(): ?string
  32. {
  33. return $this->archiveComment;
  34. }
  35. /**
  36. * Count elements of an object.
  37. *
  38. * @see https://php.net/manual/en/countable.count.php
  39. *
  40. * @return int The custom count as an integer.
  41. * The return value is cast to an integer.
  42. */
  43. public function count(): int
  44. {
  45. return \count($this->entries);
  46. }
  47. /**
  48. * When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties.
  49. * Any properties that are references to other variables, will remain references.
  50. * Once the cloning is complete, if a __clone() method is defined,
  51. * then the newly created object's __clone() method will be called, to allow any necessary properties that need to
  52. * be changed. NOT CALLABLE DIRECTLY.
  53. *
  54. * @see https://php.net/manual/en/language.oop5.cloning.php
  55. */
  56. public function __clone()
  57. {
  58. foreach ($this->entries as $key => $value) {
  59. $this->entries[$key] = clone $value;
  60. }
  61. }
  62. }