Skip to content

Commit 0d37e6b

Browse files
committed
Merge pull request #1 from nlegoff/interfaces
Describe zippy interfaces
2 parents e834abf + 0a5d98c commit 0d37e6b

File tree

7 files changed

+216
-2
lines changed

7 files changed

+216
-2
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Zippy.
5+
*
6+
* (c) Alchemy <[email protected]>
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;
13+
14+
use Alchemy\Zippy\ArchiveInterface;
15+
use Alchemy\Zippy\Exception\InvalidArgumentException;
16+
use Alchemy\Zippy\Exception\RuntimeException;
17+
use Alchemy\Zippy\Options;
18+
19+
Interface AdapterInterface
20+
{
21+
/**
22+
* Returns the adapter name
23+
*
24+
* @return String
25+
*/
26+
public function getName();
27+
28+
/**
29+
* Returns the adapter options
30+
*
31+
* @return Options
32+
*/
33+
public function getOptions();
34+
35+
/**
36+
* Sets adapter options
37+
*
38+
* @param Options $option
39+
*
40+
* @return AdapterInterface
41+
*/
42+
public function setOptions(Options $option);
43+
44+
/**
45+
* Opens an archive
46+
*
47+
* @param String $path The path to the archive
48+
*
49+
* @return ArchiveInterface
50+
*
51+
* @throws InvalidArgumentException In case the provided path is not valid
52+
* @throws RuntimeException In case of failure
53+
*/
54+
public function open($path);
55+
56+
/**
57+
* Creates a new archive
58+
*
59+
* @param String $path The path to the archive
60+
*
61+
* @return ArchiveInterface
62+
*
63+
* @throws RuntimeException In case of failure
64+
*/
65+
public function create($path);
66+
67+
/**
68+
* Tests adapter support for current environment
69+
*
70+
* @return Boolean
71+
*/
72+
public static function isSupported();
73+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Zippy.
5+
*
6+
* (c) Alchemy <[email protected]>
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;
13+
14+
use Alchemy\Zippy\Exception\InvalidArgumentException;
15+
use Alchemy\Zippy\Exception\RuntimeException;
16+
use Alchemy\Zippy\FileInterface;
17+
18+
interface ArchiveInterface
19+
{
20+
/**
21+
* Adds a file into the archive
22+
*
23+
* @param String|\SplFileInfo $source The path to the file
24+
* @param String|null $target The archive file path, null to use the same as source
25+
*
26+
* @return ArchiveInterface
27+
*
28+
* @throws InvalidArgumentException In case the provided source path is not valid
29+
* @throws RuntimeException In case of failure
30+
*/
31+
public function add($source, $target = null);
32+
33+
/**
34+
* Adds a directory into the archive
35+
36+
* @param String|\SplFileInfo $source The path to the directory
37+
* @param String|null $target The directory file path, null to use the same as source
38+
* @param Boolean $recursive Recurse into directories
39+
*
40+
* @return ArchiveInterface
41+
*
42+
* @throws InvalidArgumentException In case the provided source path is not valid
43+
* @throws RuntimeException In case of failure
44+
*/
45+
public function addDirectory($source, $target = null, $recursive = true);
46+
47+
/**
48+
* Removes a file from the archive
49+
*
50+
* @param FileInterface $file The file to remove
51+
*
52+
* @return ArchiveInterface
53+
*
54+
* @throws RuntimeException In case of failure
55+
*/
56+
public function remove(FileInterface $file);
57+
}

src/Zippy/Exception/ExceptionInterface.php renamed to src/Alchemy/Zippy/Exception/ExceptionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Zippy\Exception;
12+
namespace Alchemy\Zippy\Exception;
1313

1414
interface ExceptionInterface
1515
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Zippy.
5+
*
6+
* (c) Alchemy <[email protected]>
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\Exception;
13+
14+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
15+
{
16+
}

src/Zippy/Exception/RuntimeException.php renamed to src/Alchemy/Zippy/Exception/RuntimeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Zippy\Exception;
12+
namespace Alchemy\Zippy\Exception;
1313

1414
class RuntimeException extends \RuntimeException implements ExceptionInterface
1515
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Zippy.
5+
*
6+
* (c) Alchemy <[email protected]>
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;
13+
14+
use Alchemy\Zippy\Exception\RuntimeException;
15+
16+
class FileInterface
17+
{
18+
/**
19+
* Gets the location of a file
20+
*
21+
* @return String
22+
*/
23+
public function getLocation();
24+
25+
/**
26+
* Extracts a file from the archive to the given path
27+
*
28+
* @throws RuntimeException In case the extraction failed
29+
*/
30+
public function extract($target);
31+
32+
/**
33+
* Tells whether the current file is a directory or not
34+
*
35+
* @return Boolean
36+
*/
37+
public function isDir();
38+
39+
/**
40+
* Relocates a file with the given path
41+
*
42+
* @return FileInterface
43+
*
44+
* @throws RuntimeException In case of failure
45+
*/
46+
public function rename($location);
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function __toString();
52+
}

src/Alchemy/Zippy/Options.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Zippy.
5+
*
6+
* (c) Alchemy <[email protected]>
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;
13+
14+
class Options
15+
{
16+
}

0 commit comments

Comments
 (0)