ImmutableZipContainer.php 1.9 KB

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