Version 1
[yaffs-website] / vendor / alchemy / zippy / src / Adapter / AdapterInterface.php
1 <?php
2
3 /*
4  * This file is part of Zippy.
5  *
6  * (c) Alchemy <info@alchemy.fr>
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\Adapter;
13
14 use Alchemy\Zippy\Adapter\Resource\ResourceInterface;
15 use Alchemy\Zippy\Archive\ArchiveInterface;
16 use Alchemy\Zippy\Exception\NotSupportedException;
17 use Alchemy\Zippy\Exception\RuntimeException;
18 use Alchemy\Zippy\Exception\InvalidArgumentException;
19
20 Interface AdapterInterface
21 {
22     /**
23      * Opens an archive
24      *
25      * @param string $path The path to the archive
26      *
27      * @return ArchiveInterface
28      *
29      * @throws InvalidArgumentException In case the provided path is not valid
30      * @throws RuntimeException In case of failure
31      */
32     public function open($path);
33
34     /**
35      * Creates a new archive
36      *
37      * Please note some adapters can not create empty archives.
38      * They would throw a `NotSupportedException` in case you ask to create an archive without files
39      *
40      * @param string                            $path      The path to the archive
41      * @param string|string[]|\Traversable|null $files     A filename, an array of files, or a \Traversable instance
42      * @param bool                              $recursive Whether to recurse or not in the provided directories
43      *
44      * @return ArchiveInterface
45      *
46      * @throws RuntimeException In case of failure
47      * @throws NotSupportedException In case the operation in not supported
48      * @throws InvalidArgumentException In case no files could be added
49      */
50     public function create($path, $files = null, $recursive = true);
51
52     /**
53      * Tests if the adapter is supported by the current environment
54      *
55      * @return bool
56      */
57     public function isSupported();
58
59     /**
60      * Returns the list of all archive members
61      *
62      * @param ResourceInterface $resource The path to the archive
63      *
64      * @return array
65      *
66      * @throws RuntimeException In case of failure
67      */
68     public function listMembers(ResourceInterface $resource);
69
70     /**
71      * Adds a file to the archive
72      *
73      * @param ResourceInterface         $resource  The path to the archive
74      * @param string|array|\Traversable $files     An array of paths to add, relative to cwd
75      * @param bool                      $recursive Whether or not to recurse in the provided directories
76      *
77      * @return array
78      *
79      * @throws RuntimeException In case of failure
80      * @throws InvalidArgumentException In case no files could be added
81      */
82     public function add(ResourceInterface $resource, $files, $recursive = true);
83
84     /**
85      * Removes a member of the archive
86      *
87      * @param ResourceInterface         $resource The path to the archive
88      * @param string|array|\Traversable $files    A filename, an array of files, or a \Traversable instance
89      *
90      * @return array
91      *
92      * @throws RuntimeException In case of failure
93      * @throws InvalidArgumentException In case no files could be removed
94      */
95     public function remove(ResourceInterface $resource, $files);
96
97     /**
98      * Extracts an entire archive
99      *
100      * Note that any existing files will be overwritten by the adapter
101      *
102      * @param ResourceInterface $resource The path to the archive
103      * @param string|null       $to       The path where to extract the archive
104      *
105      * @return \SplFileInfo The extracted archive
106      *
107      * @throws RuntimeException In case of failure
108      * @throws InvalidArgumentException In case the provided path where to extract the archive is not valid
109      */
110     public function extract(ResourceInterface $resource, $to = null);
111
112     /**
113      * Extracts specific members of the archive
114      *
115      * @param ResourceInterface $resource  The path to the archive
116      * @param string|string[]   $members   A path or array of paths matching the members to extract from the resource.
117      * @param string|null       $to        The path where to extract the members
118      * @param bool              $overwrite Whether to overwrite existing files in target directory
119      *
120      * @return \SplFileInfo The extracted archive
121      *
122      * @throws RuntimeException In case of failure
123      * @throws InvalidArgumentException In case no members could be removed or providedd extract target directory is not valid
124      */
125     public function extractMembers(ResourceInterface $resource, $members, $to = null, $overwrite = false);
126
127     /**
128      * Returns the adapter name
129      *
130      * @return string
131      */
132     public static function getName();
133 }