4 * This file is part of Zippy.
6 * (c) Alchemy <info@alchemy.fr>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Alchemy\Zippy\Adapter;
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;
20 Interface AdapterInterface
25 * @param string $path The path to the archive
27 * @return ArchiveInterface
29 * @throws InvalidArgumentException In case the provided path is not valid
30 * @throws RuntimeException In case of failure
32 public function open($path);
35 * Creates a new archive
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
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
44 * @return ArchiveInterface
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
50 public function create($path, $files = null, $recursive = true);
53 * Tests if the adapter is supported by the current environment
57 public function isSupported();
60 * Returns the list of all archive members
62 * @param ResourceInterface $resource The path to the archive
66 * @throws RuntimeException In case of failure
68 public function listMembers(ResourceInterface $resource);
71 * Adds a file to the archive
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
79 * @throws RuntimeException In case of failure
80 * @throws InvalidArgumentException In case no files could be added
82 public function add(ResourceInterface $resource, $files, $recursive = true);
85 * Removes a member of the archive
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
92 * @throws RuntimeException In case of failure
93 * @throws InvalidArgumentException In case no files could be removed
95 public function remove(ResourceInterface $resource, $files);
98 * Extracts an entire archive
100 * Note that any existing files will be overwritten by the adapter
102 * @param ResourceInterface $resource The path to the archive
103 * @param string|null $to The path where to extract the archive
105 * @return \SplFileInfo The extracted archive
107 * @throws RuntimeException In case of failure
108 * @throws InvalidArgumentException In case the provided path where to extract the archive is not valid
110 public function extract(ResourceInterface $resource, $to = null);
113 * Extracts specific members of the archive
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
120 * @return \SplFileInfo The extracted archive
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
125 public function extractMembers(ResourceInterface $resource, $members, $to = null, $overwrite = false);
128 * Returns the adapter name
132 public static function getName();