1 | <?php |
||
30 | class Zippy |
||
31 | { |
||
32 | /** |
||
33 | * @var AdapterContainer |
||
34 | */ |
||
35 | public $adapters; |
||
36 | |||
37 | /** |
||
38 | * @var FileStrategyInterface[][] |
||
39 | */ |
||
40 | private $strategies = array(); |
||
41 | |||
42 | public function __construct(AdapterContainer $adapters) |
||
46 | |||
47 | /** |
||
48 | * Creates an archive |
||
49 | * |
||
50 | * @param string $path |
||
51 | * @param string|array|\Traversable|null $files |
||
52 | * @param bool $recursive |
||
53 | * @param string|null $type |
||
54 | * |
||
55 | * @return ArchiveInterface |
||
56 | * |
||
57 | * @throws RuntimeException In case of failure |
||
58 | */ |
||
59 | public function create($path, $files = null, $recursive = true, $type = null) |
||
73 | |||
74 | /** |
||
75 | * Opens an archive. |
||
76 | * |
||
77 | * @param string $path |
||
78 | * |
||
79 | * @return ArchiveInterface |
||
80 | * |
||
81 | * @throws RuntimeException In case of failure |
||
82 | */ |
||
83 | public function open($path, $type = null) |
||
97 | |||
98 | /** |
||
99 | * Adds a strategy. |
||
100 | * |
||
101 | * The last strategy added is preferred over the other ones. |
||
102 | * You can add a strategy twice ; when doing this, the first one is removed |
||
103 | * when inserting the second one. |
||
104 | * |
||
105 | * @param FileStrategyInterface $strategy |
||
106 | * |
||
107 | * @return Zippy |
||
108 | */ |
||
109 | public function addStrategy(FileStrategyInterface $strategy) |
||
125 | |||
126 | /** |
||
127 | * Returns the strategies as they are stored |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | public function getStrategies() |
||
135 | |||
136 | /** |
||
137 | * Returns an adapter for a file extension |
||
138 | * |
||
139 | * @param string $extension The extension |
||
140 | * |
||
141 | * @return AdapterInterface |
||
142 | * |
||
143 | * @throws FormatNotSupportedException When no strategy is defined for this extension |
||
144 | * @throws NoAdapterOnPlatformException When no adapter is supported for this extension on this platform |
||
145 | */ |
||
146 | public function getAdapterFor($extension) |
||
164 | |||
165 | /** |
||
166 | * Creates Zippy and loads default strategies |
||
167 | * |
||
168 | * @return Zippy |
||
169 | */ |
||
170 | public static function load() |
||
185 | |||
186 | /** |
||
187 | * Sanitize an extension. |
||
188 | * |
||
189 | * Strips dot from the beginning, converts to lowercase and remove trailing |
||
190 | * whitespaces |
||
191 | * |
||
192 | * @param string $extension |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | private function sanitizeExtension($extension) |
||
200 | |||
201 | /** |
||
202 | * Finds an extension that has strategy registered given a file path |
||
203 | * |
||
204 | * Returns null if no matching strategy found. |
||
205 | * |
||
206 | * @param string $path |
||
207 | * |
||
208 | * @return string|null |
||
209 | */ |
||
210 | private function guessAdapterExtension($path) |
||
222 | } |
||
223 |