From a428eaf9eacf3fa47426b2c956269c5c2a8ca55b Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 2 Jan 2013 16:37:13 +0100 Subject: [PATCH 1/3] Add alchemy namespace --- src/{ => Alchemy}/Zippy/Exception/ExceptionInterface.php | 2 +- src/{ => Alchemy}/Zippy/Exception/RuntimeException.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{ => Alchemy}/Zippy/Exception/ExceptionInterface.php (87%) rename src/{ => Alchemy}/Zippy/Exception/RuntimeException.php (89%) 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/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 { From 644e5077440abe4db9608900409941bfd3ddfc3f Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 2 Jan 2013 16:37:34 +0100 Subject: [PATCH 2/3] Add zippy interfaces Add option class file header Fix typo Fix typo --- src/Alchemy/Zippy/AdapterInterface.php | 74 ++++++++++++++++++++++++++ src/Alchemy/Zippy/ArchiveInterface.php | 57 ++++++++++++++++++++ src/Alchemy/Zippy/FileInterface.php | 52 ++++++++++++++++++ src/Alchemy/Zippy/Options.php | 16 ++++++ 4 files changed, 199 insertions(+) create mode 100644 src/Alchemy/Zippy/AdapterInterface.php create mode 100644 src/Alchemy/Zippy/ArchiveInterface.php create mode 100644 src/Alchemy/Zippy/FileInterface.php create mode 100644 src/Alchemy/Zippy/Options.php diff --git a/src/Alchemy/Zippy/AdapterInterface.php b/src/Alchemy/Zippy/AdapterInterface.php new file mode 100644 index 0000000..ebe4d1c --- /dev/null +++ b/src/Alchemy/Zippy/AdapterInterface.php @@ -0,0 +1,74 @@ + + * + * 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 of 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..7efe40c --- /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 $target The archive file path, null to use the same as source + * + * @return ArchiveInterface + * + * @throws InvalidArgumentException in case of 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 $target The directory file path, null to use the same as source + * @param Boolean $recursive Recurse into directories + * + * @return ArchiveInterface + * + * @throws InvalidArgumentException in case of 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/Alchemy/Zippy/FileInterface.php b/src/Alchemy/Zippy/FileInterface.php new file mode 100644 index 0000000..44677f3 --- /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 of 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 +{ +} From 0a5d98c812e2b0b14907f1e238bf7a771010d50b Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 2 Jan 2013 18:10:41 +0100 Subject: [PATCH 3/3] Add invalid agument exception Fix CS Fix typo Fix CS --- src/Alchemy/Zippy/AdapterInterface.php | 45 +++++++++--------- src/Alchemy/Zippy/ArchiveInterface.php | 46 +++++++++---------- .../Exception/InvalidArgumentException.php | 16 +++++++ src/Alchemy/Zippy/FileInterface.php | 22 ++++----- 4 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 src/Alchemy/Zippy/Exception/InvalidArgumentException.php diff --git a/src/Alchemy/Zippy/AdapterInterface.php b/src/Alchemy/Zippy/AdapterInterface.php index ebe4d1c..a276930 100644 --- a/src/Alchemy/Zippy/AdapterInterface.php +++ b/src/Alchemy/Zippy/AdapterInterface.php @@ -21,46 +21,46 @@ /** * Returns the adapter name * - * @return String + * @return String */ public function getName(); - + /** * Returns the adapter options * - * @return Options + * @return Options */ public function getOptions(); - + /** * Sets adapter options - * - * @param Options $option - * - * @return AdapterInterface + * + * @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 of the provided path is not valid - * @throws RuntimeException in case of failure + * + * @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 + * + * @param String $path The path to the archive + * + * @return ArchiveInterface + * + * @throws RuntimeException In case of failure */ public function create($path); @@ -70,5 +70,4 @@ public function create($path); * @return Boolean */ public static function isSupported(); - } diff --git a/src/Alchemy/Zippy/ArchiveInterface.php b/src/Alchemy/Zippy/ArchiveInterface.php index 7efe40c..ce6a5e4 100644 --- a/src/Alchemy/Zippy/ArchiveInterface.php +++ b/src/Alchemy/Zippy/ArchiveInterface.php @@ -19,39 +19,39 @@ interface ArchiveInterface { /** * Adds a file into the archive - * - * @param String|\SplFileInfo $source The path to the file - * @param String $target The archive file path, null to use the same as source - * - * @return ArchiveInterface - * - * @throws InvalidArgumentException in case of the provided source path is not valid - * @throws RuntimeException in case of failure + * + * @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 $target The directory file path, null to use the same as source - * @param Boolean $recursive Recurse into directories - * - * @return ArchiveInterface - * - * @throws InvalidArgumentException in case of the provided source path is not valid - * @throws RuntimeException in case of failure + * @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 + * + * @param FileInterface $file The file to remove + * + * @return ArchiveInterface + * + * @throws RuntimeException In case of failure */ public function remove(FileInterface $file); } 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/Alchemy/Zippy/FileInterface.php b/src/Alchemy/Zippy/FileInterface.php index 44677f3..019c56e 100644 --- a/src/Alchemy/Zippy/FileInterface.php +++ b/src/Alchemy/Zippy/FileInterface.php @@ -17,34 +17,34 @@ 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 of the extraction failed + * + * @throws RuntimeException In case the extraction failed */ public function extract($target); /** * Tells whether the current file is a directory or not - * - * @return Boolean + * + * @return Boolean */ public function isDir(); - + /** * Relocates a file with the given path - * + * * @return FileInterface - * - * @throws RuntimeException in case of failure + * + * @throws RuntimeException In case of failure */ public function rename($location); - + /** * @inheritdoc */