1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Zippy. |
5
|
|
|
* |
6
|
|
|
* (c) Alchemy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Alchemy\Zippy\Archive; |
13
|
|
|
|
14
|
|
|
use Alchemy\Zippy\Adapter\AdapterInterface; |
15
|
|
|
use Alchemy\Zippy\Resource\ResourceManager; |
16
|
|
|
use Alchemy\Zippy\Adapter\Resource\ResourceInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Represents an archive |
20
|
|
|
*/ |
21
|
|
|
class Archive implements ArchiveInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The path to the archive |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $path; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The archive adapter |
32
|
|
|
* |
33
|
|
|
* @var AdapterInterface |
34
|
|
|
*/ |
35
|
|
|
protected $adapter; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* An array of archive members |
39
|
|
|
* |
40
|
|
|
* @var MemberInterface[] |
41
|
|
|
*/ |
42
|
|
|
protected $members = array(); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var ResourceInterface |
46
|
|
|
*/ |
47
|
|
|
protected $resource; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* |
51
|
|
|
* @var ResourceManager |
52
|
|
|
*/ |
53
|
|
|
protected $manager; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Constructor |
57
|
|
|
* |
58
|
|
|
* @param ResourceInterface $resource Path to the archive |
59
|
|
|
* @param AdapterInterface $adapter An archive adapter |
60
|
|
|
* @param ResourceManager $manager The resource manager |
61
|
|
|
*/ |
62
|
|
|
public function __construct(ResourceInterface $resource, AdapterInterface $adapter, ResourceManager $manager) |
63
|
|
|
{ |
64
|
|
|
$this->resource = $resource; |
65
|
|
|
$this->adapter = $adapter; |
66
|
|
|
$this->manager = $manager; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritdoc |
71
|
|
|
*/ |
72
|
|
|
public function count() |
73
|
|
|
{ |
74
|
|
|
return count($this->getMembers()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns an Iterator for the current archive |
79
|
|
|
* |
80
|
|
|
* This method implements the IteratorAggregate interface. |
81
|
|
|
* |
82
|
|
|
* @return \ArrayIterator|MemberInterface[] An iterator |
83
|
|
|
*/ |
84
|
|
|
public function getIterator() |
85
|
|
|
{ |
86
|
|
|
return new \ArrayIterator($this->getMembers()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @inheritdoc |
91
|
|
|
*/ |
92
|
|
|
public function getMembers() |
93
|
|
|
{ |
94
|
|
|
return $this->members = $this->adapter->listMembers($this->resource); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritdoc |
99
|
|
|
*/ |
100
|
|
|
public function addMembers($sources, $recursive = true) |
101
|
|
|
{ |
102
|
|
|
$this->adapter->add($this->resource, $sources, $recursive); |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritdoc |
109
|
|
|
*/ |
110
|
|
|
public function removeMembers($sources) |
111
|
|
|
{ |
112
|
|
|
$this->adapter->remove($this->resource, $sources); |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @inheritdoc |
119
|
|
|
*/ |
120
|
|
|
public function extract($toDirectory) |
121
|
|
|
{ |
122
|
|
|
$this->adapter->extract($this->resource, $toDirectory); |
123
|
|
|
|
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @inheritdoc |
129
|
|
|
*/ |
130
|
|
|
public function extractMembers($members, $toDirectory = null) |
131
|
|
|
{ |
132
|
|
|
$this->adapter->extractMembers($this->resource, $members, $toDirectory); |
|
|
|
|
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.