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