酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ImmutableZipContainer.php 1.7 KiB

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