diff --git a/src/Alchemy/Zippy/AdapterInterface.php b/src/Alchemy/Zippy/AdapterInterface.php new file mode 100644 index 0000000..a276930 --- /dev/null +++ b/src/Alchemy/Zippy/AdapterInterface.php @@ -0,0 +1,73 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Zippy; + +use Alchemy\Zippy\ArchiveInterface; +use Alchemy\Zippy\Exception\InvalidArgumentException; +use Alchemy\Zippy\Exception\RuntimeException; +use Alchemy\Zippy\Options; + +Interface AdapterInterface +{ + /** + * Returns the adapter name + * + * @return String + */ + public function getName(); + + /** + * Returns the adapter options + * + * @return Options + */ + public function getOptions(); + + /** + * Sets adapter options + * + * @param Options $option + * + * @return AdapterInterface + */ + public function setOptions(Options $option); + + /** + * Opens an archive + * + * @param String $path The path to the archive + * + * @return ArchiveInterface + * + * @throws InvalidArgumentException In case the provided path is not valid + * @throws RuntimeException In case of failure + */ + public function open($path); + + /** + * Creates a new archive + * + * @param String $path The path to the archive + * + * @return ArchiveInterface + * + * @throws RuntimeException In case of failure + */ + public function create($path); + + /** + * Tests adapter support for current environment + * + * @return Boolean + */ + public static function isSupported(); +} diff --git a/src/Alchemy/Zippy/ArchiveInterface.php b/src/Alchemy/Zippy/ArchiveInterface.php new file mode 100644 index 0000000..ce6a5e4 --- /dev/null +++ b/src/Alchemy/Zippy/ArchiveInterface.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Zippy; + +use Alchemy\Zippy\Exception\InvalidArgumentException; +use Alchemy\Zippy\Exception\RuntimeException; +use Alchemy\Zippy\FileInterface; + +interface ArchiveInterface +{ + /** + * Adds a file into the archive + * + * @param String|\SplFileInfo $source The path to the file + * @param String|null $target The archive file path, null to use the same as source + * + * @return ArchiveInterface + * + * @throws InvalidArgumentException In case the provided source path is not valid + * @throws RuntimeException In case of failure + */ + public function add($source, $target = null); + + /** + * Adds a directory into the archive + + * @param String|\SplFileInfo $source The path to the directory + * @param String|null $target The directory file path, null to use the same as source + * @param Boolean $recursive Recurse into directories + * + * @return ArchiveInterface + * + * @throws InvalidArgumentException In case the provided source path is not valid + * @throws RuntimeException In case of failure + */ + public function addDirectory($source, $target = null, $recursive = true); + + /** + * Removes a file from the archive + * + * @param FileInterface $file The file to remove + * + * @return ArchiveInterface + * + * @throws RuntimeException In case of failure + */ + public function remove(FileInterface $file); +} diff --git a/src/Zippy/Exception/ExceptionInterface.php b/src/Alchemy/Zippy/Exception/ExceptionInterface.php similarity index 87% rename from src/Zippy/Exception/ExceptionInterface.php rename to src/Alchemy/Zippy/Exception/ExceptionInterface.php index 658d5fd..832d2eb 100644 --- a/src/Zippy/Exception/ExceptionInterface.php +++ b/src/Alchemy/Zippy/Exception/ExceptionInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Zippy\Exception; +namespace Alchemy\Zippy\Exception; interface ExceptionInterface { diff --git a/src/Alchemy/Zippy/Exception/InvalidArgumentException.php b/src/Alchemy/Zippy/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..c901135 --- /dev/null +++ b/src/Alchemy/Zippy/Exception/InvalidArgumentException.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Zippy\Exception; + +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/src/Zippy/Exception/RuntimeException.php b/src/Alchemy/Zippy/Exception/RuntimeException.php similarity index 89% rename from src/Zippy/Exception/RuntimeException.php rename to src/Alchemy/Zippy/Exception/RuntimeException.php index bc05c95..a6aa517 100644 --- a/src/Zippy/Exception/RuntimeException.php +++ b/src/Alchemy/Zippy/Exception/RuntimeException.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Zippy\Exception; +namespace Alchemy\Zippy\Exception; class RuntimeException extends \RuntimeException implements ExceptionInterface { diff --git a/src/Alchemy/Zippy/FileInterface.php b/src/Alchemy/Zippy/FileInterface.php new file mode 100644 index 0000000..019c56e --- /dev/null +++ b/src/Alchemy/Zippy/FileInterface.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Zippy; + +use Alchemy\Zippy\Exception\RuntimeException; + +class FileInterface +{ + /** + * Gets the location of a file + * + * @return String + */ + public function getLocation(); + + /** + * Extracts a file from the archive to the given path + * + * @throws RuntimeException In case the extraction failed + */ + public function extract($target); + + /** + * Tells whether the current file is a directory or not + * + * @return Boolean + */ + public function isDir(); + + /** + * Relocates a file with the given path + * + * @return FileInterface + * + * @throws RuntimeException In case of failure + */ + public function rename($location); + + /** + * @inheritdoc + */ + public function __toString(); +} diff --git a/src/Alchemy/Zippy/Options.php b/src/Alchemy/Zippy/Options.php new file mode 100644 index 0000000..10c0a69 --- /dev/null +++ b/src/Alchemy/Zippy/Options.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Zippy; + +class Options +{ +}