diff --git a/.travis.yml b/.travis.yml index 8ad53bc..6bc6434 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ php: - "5.5" - "5.4" - "5.3" - - "5.2" before_script: - chmod 777 Tests/tmp diff --git a/README.md b/README.md index 40e5c41..f2b0bdb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Работа с 7z архивами с помощью командной строки. -[![Build Status](https://secure.travis-ci.org/Gemorroj/Archive_7z.png?branch=master)](https://travis-ci.org/Gemorroj/Archive_7z) +[![Build Status](https://secure.travis-ci.org/Gemorroj/Archive7z.png?branch=master)](https://travis-ci.org/Gemorroj/Archive7z) На данный момент, поддерживается распаковка всего архива, @@ -12,7 +12,7 @@ Требования: -- PHP >= 5.2 +- PHP >= 5.3 - shell - 7z >= 7.30 @@ -20,10 +20,7 @@ Пример: ```php setOutputDirectory('./test'); foreach ($obj->getEntries() as $v) { diff --git a/Tests/7z/Archive_7z_EntryTest.php b/Tests/7z/Archive_7z_EntryTest.php deleted file mode 100644 index 1020f41..0000000 --- a/Tests/7z/Archive_7z_EntryTest.php +++ /dev/null @@ -1,10 +0,0 @@ -assertInstanceOf('Exception', new Archive_7z_Exception); - } -} diff --git a/Tests/Archive_7zTest.php b/Tests/Archive7z/Archive7zTest.php similarity index 60% rename from Tests/Archive_7zTest.php rename to Tests/Archive7z/Archive7zTest.php index 8ce878a..177b7a7 100644 --- a/Tests/Archive_7zTest.php +++ b/Tests/Archive7z/Archive7zTest.php @@ -1,20 +1,22 @@ tmpDir = dirname(__FILE__) . '/tmp'; - $this->mock = $this->getMock('Archive_7z', null, array('fake.7z', $this->cliPath)); + $this->mock = $this->getMock('Archive7z\Archive7z', null, array('fake.7z', $this->cliPath)); } protected function tearDown() @@ -45,13 +47,13 @@ public function testSetGetCli() $cli = $this->mock->getCli(); $result = $this->mock->setCli($cli); - $this->assertInstanceOf('Archive_7z', $result); + $this->assertInstanceOf('Archive7z\Archive7z', $result); $this->assertEquals(realpath($cli), $this->mock->getCli()); } public function testSetCliFail() { - $this->setExpectedException('Archive_7z_Exception'); + $this->setExpectedException('Archive7z\Exception'); $this->mock->setCli('./fake_path'); } @@ -60,21 +62,21 @@ public function testSetGetFilename() { $filename = '/custom_path/test.7z'; $result = $this->mock->setFilename($filename); - $this->assertInstanceOf('Archive_7z', $result); + $this->assertInstanceOf('Archive7z\Archive7z', $result); $this->assertEquals($filename, $this->mock->getFilename()); } public function testSetGetOutputDirectory() { $result = $this->mock->setOutputDirectory($this->tmpDir); - $this->assertInstanceOf('Archive_7z', $result); + $this->assertInstanceOf('Archive7z\Archive7z', $result); $this->assertEquals(realpath($this->tmpDir), $this->mock->getOutputDirectory()); } public function testSetGetOutputDirectoryFail() { $outputDirectory = '/fake_path/test'; - $this->setExpectedException('Archive_7z_Exception'); + $this->setExpectedException('Archive7z\Exception'); $this->mock->setOutputDirectory($outputDirectory); } @@ -82,28 +84,28 @@ public function testSetGetPassword() { $password = 'passw'; $result = $this->mock->setPassword($password); - $this->assertInstanceOf('Archive_7z', $result); + $this->assertInstanceOf('Archive7z\Archive7z', $result); $this->assertEquals($password, $this->mock->getPassword()); } public function testSetGetOverwriteMode() { - $result = $this->mock->setOverwriteMode(Archive_7z::OVERWRITE_MODE_U); - $this->assertInstanceOf('Archive_7z', $result); - $this->assertEquals(Archive_7z::OVERWRITE_MODE_U, $this->mock->getOverwriteMode()); + $result = $this->mock->setOverwriteMode(Archive7z::OVERWRITE_MODE_U); + $this->assertInstanceOf('Archive7z\Archive7z', $result); + $this->assertEquals(Archive7z::OVERWRITE_MODE_U, $this->mock->getOverwriteMode()); } public function testExtract() { - $obj = new Archive_7z(dirname(__FILE__) . '/test.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/test.7z', $this->cliPath); $obj->setOutputDirectory($this->tmpDir); $obj->extract(); } public function testExtractPasswd() { - $obj = new Archive_7z(dirname(__FILE__) . '/testPasswd.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/testPasswd.7z', $this->cliPath); $obj->setOutputDirectory($this->tmpDir); $obj->setPassword('123'); $obj->extract(); @@ -112,27 +114,27 @@ public function testExtractPasswd() public function testExtractOverwrite() { mkdir($this->tmpDir . '/test'); - $sourceFile = dirname(__FILE__) . '/test.txt'; + $sourceFile = __DIR__ . '/test.txt'; $targetFile = $this->tmpDir . '/test/test.txt'; - $archiveFile = dirname(__FILE__) . '/testArchive.txt'; + $archiveFile = __DIR__ . '/testArchive.txt'; - $obj = new Archive_7z(dirname(__FILE__) . '/test.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/test.7z', $this->cliPath); $obj->setOutputDirectory($this->tmpDir); - $obj->setOverwriteMode(Archive_7z::OVERWRITE_MODE_A); + $obj->setOverwriteMode(Archive7z::OVERWRITE_MODE_A); copy($sourceFile, $targetFile); $obj->extract(); $this->assertFileEquals($archiveFile, $targetFile); - $obj->setOverwriteMode(Archive_7z::OVERWRITE_MODE_S); + $obj->setOverwriteMode(Archive7z::OVERWRITE_MODE_S); copy($sourceFile, $targetFile); $obj->extract(); $this->assertFileEquals($sourceFile, $targetFile); - $obj->setOverwriteMode(Archive_7z::OVERWRITE_MODE_T); + $obj->setOverwriteMode(Archive7z::OVERWRITE_MODE_T); copy($sourceFile, $targetFile); $obj->extract(); $this->assertFileExists($this->tmpDir . '/test/test_1.txt'); @@ -141,7 +143,7 @@ public function testExtractOverwrite() unlink($this->tmpDir . '/test/test_1.txt'); - $obj->setOverwriteMode(Archive_7z::OVERWRITE_MODE_U); + $obj->setOverwriteMode(Archive7z::OVERWRITE_MODE_U); copy($sourceFile, $targetFile); $obj->extract(); $this->assertFileExists($this->tmpDir . '/test/test_1.txt'); @@ -153,7 +155,7 @@ public function testExtractOverwrite() public function testExtractEntry() { - $obj = new Archive_7z(dirname(__FILE__) . '/test.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/test.7z', $this->cliPath); $obj->setOutputDirectory($this->tmpDir); $obj->extractEntry('test/2.jpg'); } @@ -161,27 +163,27 @@ public function testExtractEntry() public function testExtractEntryOverwrite() { mkdir($this->tmpDir . '/test'); - $sourceFile = dirname(__FILE__) . '/test.txt'; + $sourceFile = __DIR__ . '/test.txt'; $targetFile = $this->tmpDir . '/test/test.txt'; - $archiveFile = dirname(__FILE__) . '/testArchive.txt'; + $archiveFile = __DIR__ . '/testArchive.txt'; - $obj = new Archive_7z(dirname(__FILE__) . '/test.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/test.7z', $this->cliPath); $obj->setOutputDirectory($this->tmpDir); - $obj->setOverwriteMode(Archive_7z::OVERWRITE_MODE_A); + $obj->setOverwriteMode(Archive7z::OVERWRITE_MODE_A); copy($sourceFile, $targetFile); $obj->extractEntry('test/test.txt'); $this->assertFileEquals($archiveFile, $targetFile); - $obj->setOverwriteMode(Archive_7z::OVERWRITE_MODE_S); + $obj->setOverwriteMode(Archive7z::OVERWRITE_MODE_S); copy($sourceFile, $targetFile); $obj->extractEntry('test/test.txt'); $this->assertFileEquals($sourceFile, $targetFile); - $obj->setOverwriteMode(Archive_7z::OVERWRITE_MODE_T); + $obj->setOverwriteMode(Archive7z::OVERWRITE_MODE_T); copy($sourceFile, $targetFile); $obj->extractEntry('test/test.txt'); $this->assertFileExists($this->tmpDir . '/test/test_1.txt'); @@ -190,7 +192,7 @@ public function testExtractEntryOverwrite() unlink($this->tmpDir . '/test/test_1.txt'); - $obj->setOverwriteMode(Archive_7z::OVERWRITE_MODE_U); + $obj->setOverwriteMode(Archive7z::OVERWRITE_MODE_U); copy($sourceFile, $targetFile); $obj->extractEntry('test/test.txt'); $this->assertFileExists($this->tmpDir . '/test/test_1.txt'); @@ -203,7 +205,7 @@ public function testExtractEntryOverwrite() public function testExtractEntryUnicode() { $file = iconv('UTF-8', 'Windows-1251', 'чавес.jpg'); - $obj = new Archive_7z(dirname(__FILE__) . '/test.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/test.7z', $this->cliPath); $obj->setOutputDirectory($this->tmpDir); $obj->extractEntry($file); $result = is_file($this->tmpDir . '/' . $file); @@ -212,7 +214,7 @@ public function testExtractEntryUnicode() public function testExtractEntryPasswd() { - $obj = new Archive_7z(dirname(__FILE__) . '/testPasswd.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/testPasswd.7z', $this->cliPath); $obj->setOutputDirectory($this->tmpDir); $obj->setPassword('123'); $obj->extractEntry('1.jpg'); @@ -220,125 +222,125 @@ public function testExtractEntryPasswd() public function testGetContentPasswd() { - $obj = new Archive_7z(dirname(__FILE__) . '/testPasswd.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/testPasswd.7z', $this->cliPath); $obj->setPassword('123'); $result = $obj->getContent('test/test.txt'); - $this->assertEquals(file_get_contents(dirname(__FILE__) . '/testArchive.txt'), $result); + $this->assertEquals(file_get_contents(__DIR__ . '/testArchive.txt'), $result); } public function testGetEntriesPasswd() { - $obj = new Archive_7z(dirname(__FILE__) . '/testPasswd.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/testPasswd.7z', $this->cliPath); $obj->setPassword('123'); $result = $obj->getEntries(); $this->assertTrue(is_array($result)); $this->assertCount(5, $result); // 4 file + 1 directory - $this->assertInstanceOf('Archive_7z_Entry', $result[0]); + $this->assertInstanceOf('Archive7z\Entry', $result[0]); } public function testGetEntryPasswd() { - $obj = new Archive_7z(dirname(__FILE__) . '/testPasswd.7z', $this->cliPath); + $obj = new Archive7z(__DIR__ . '/testPasswd.7z', $this->cliPath); $obj->setPassword('123'); $result = $obj->getEntry('test' . DIRECTORY_SEPARATOR . 'test.txt'); - $this->assertInstanceOf('Archive_7z_Entry', $result); + $this->assertInstanceOf('Archive7z\Entry', $result); } public function testAddEntryFullPathPasswd() { - //copy(dirname(__FILE__) . '/test.7z', $this->tmpDir . '/test.7z'); - copy(dirname(__FILE__) . '/test.txt', $this->tmpDir . '/file.txt'); + //copy(__DIR__ . '/test.7z', $this->tmpDir . '/test.7z'); + copy(__DIR__ . '/test.txt', $this->tmpDir . '/file.txt'); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->setPassword('111'); $obj->addEntry(realpath($this->tmpDir . '/file.txt'), false, false); $result = $obj->getEntry('file.txt'); - $this->assertInstanceOf('Archive_7z_Entry', $result); + $this->assertInstanceOf('Archive7z\Entry', $result); $this->assertEquals('file.txt', $result->getPath()); - $new = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); - $this->setExpectedException('Archive_7z_Exception'); + $new = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); + $this->setExpectedException('Archive7z\Exception'); $new->getContent('file.txt'); } public function testAddEntryFullPath() { - //copy(dirname(__FILE__) . '/test.7z', $this->tmpDir . '/test.7z'); - copy(dirname(__FILE__) . '/test.txt', $this->tmpDir . '/file.txt'); + //copy(__DIR__ . '/test.7z', $this->tmpDir . '/test.7z'); + copy(__DIR__ . '/test.txt', $this->tmpDir . '/file.txt'); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->addEntry(realpath($this->tmpDir . '/file.txt'), false, false); $result = $obj->getEntry('file.txt'); - $this->assertInstanceOf('Archive_7z_Entry', $result); + $this->assertInstanceOf('Archive7z\Entry', $result); $this->assertEquals('file.txt', $result->getPath()); } public function testAddEntryFullPathStore() { - //copy(dirname(__FILE__) . '/test.7z', $this->tmpDir . '/test.7z'); - copy(dirname(__FILE__) . '/test.txt', $this->tmpDir . '/file.txt'); + //copy(__DIR__ . '/test.7z', $this->tmpDir . '/test.7z'); + copy(__DIR__ . '/test.txt', $this->tmpDir . '/file.txt'); $fullPath = realpath($this->tmpDir . '/file.txt'); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->addEntry($fullPath, false, true); $result = $obj->getEntry($fullPath); - $this->assertInstanceOf('Archive_7z_Entry', $result); + $this->assertInstanceOf('Archive7z\Entry', $result); $this->assertEquals($fullPath, $result->getPath()); } public function testAddEntryLocalPath() { - //copy(dirname(__FILE__) . '/test.7z', $this->tmpDir . '/test.7z'); - copy(dirname(__FILE__) . '/test.txt', $this->tmpDir . '/test.txt'); - $localPath = basename(dirname(__FILE__)) . DIRECTORY_SEPARATOR . basename($this->tmpDir) . DIRECTORY_SEPARATOR . 'test.txt'; + //copy(__DIR__ . '/test.7z', $this->tmpDir . '/test.7z'); + copy(__DIR__ . '/test.txt', $this->tmpDir . '/test.txt'); + $localPath = basename(__DIR__) . DIRECTORY_SEPARATOR . basename($this->tmpDir) . DIRECTORY_SEPARATOR . 'test.txt'; - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->addEntry($localPath, false, true); $result = $obj->getEntry($localPath); - $this->assertInstanceOf('Archive_7z_Entry', $result); + $this->assertInstanceOf('Archive7z\Entry', $result); $this->assertEquals($localPath, $result->getPath()); } public function testAddEntryLocalPathSubFiles() { mkdir($this->tmpDir . '/test'); - copy(dirname(__FILE__) . '/test.txt', $this->tmpDir . '/test/test.txt'); - $localPath = basename(dirname(__FILE__)) . DIRECTORY_SEPARATOR . basename($this->tmpDir); + copy(__DIR__ . '/test.txt', $this->tmpDir . '/test/test.txt'); + $localPath = basename(__DIR__) . DIRECTORY_SEPARATOR . basename($this->tmpDir); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->addEntry($localPath, true, true); $result = $obj->getEntry($localPath); - $this->assertInstanceOf('Archive_7z_Entry', $result); + $this->assertInstanceOf('Archive7z\Entry', $result); $this->assertEquals($localPath, $result->getPath()); } public function testAddEntryFullPathSubFiles() { mkdir($this->tmpDir . '/test'); - copy(dirname(__FILE__) . '/test.txt', $this->tmpDir . '/test/test.txt'); + copy(__DIR__ . '/test.txt', $this->tmpDir . '/test/test.txt'); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->addEntry(realpath($this->tmpDir), true, false); $result = $obj->getEntry(basename($this->tmpDir)); - $this->assertInstanceOf('Archive_7z_Entry', $result); + $this->assertInstanceOf('Archive7z\Entry', $result); $this->assertEquals(basename($this->tmpDir), $result->getPath()); } public function testDelEntry() { - copy(dirname(__FILE__) . '/test.7z', $this->tmpDir . '/test.7z'); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + copy(__DIR__ . '/test.7z', $this->tmpDir . '/test.7z'); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->delEntry('test/test.txt'); $this->assertNull($obj->getEntry('test/test.txt')); } public function testDelEntryPasswd() { - copy(dirname(__FILE__) . '/testPasswd.7z', $this->tmpDir . '/test.7z'); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + copy(__DIR__ . '/testPasswd.7z', $this->tmpDir . '/test.7z'); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->setPassword('123'); $obj->delEntry('test/test.txt'); $this->assertNull($obj->getEntry('test/test.txt')); @@ -346,21 +348,21 @@ public function testDelEntryPasswd() public function testDelEntryPasswdFail() { - copy(dirname(__FILE__) . '/testPasswd.7z', $this->tmpDir . '/test.7z'); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); - $this->setExpectedException('Archive_7z_Exception'); + copy(__DIR__ . '/testPasswd.7z', $this->tmpDir . '/test.7z'); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); + $this->setExpectedException('Archive7z\Exception'); $obj->delEntry('test/test.txt'); } public function testRenameEntryPasswd() { - copy(dirname(__FILE__) . '/testPasswd.7z', $this->tmpDir . '/test.7z'); - $obj = new Archive_7z($this->tmpDir . '/test.7z', $this->cliPath); + copy(__DIR__ . '/testPasswd.7z', $this->tmpDir . '/test.7z'); + $obj = new Archive7z($this->tmpDir . '/test.7z', $this->cliPath); $obj->setPassword('123'); $obj->renameEntry('test' . DIRECTORY_SEPARATOR . 'test.txt', 'test' . DIRECTORY_SEPARATOR . 'newTest.txt'); $resultSrc = $obj->getEntry('test' . DIRECTORY_SEPARATOR . 'test.txt'); $this->assertNull($resultSrc); $resultDest = $obj->getEntry('test' . DIRECTORY_SEPARATOR . 'newTest.txt'); - $this->assertInstanceOf('Archive_7z_Entry', $resultDest); + $this->assertInstanceOf('Archive7z\Entry', $resultDest); } } diff --git a/Tests/Archive7z/EntryTest.php b/Tests/Archive7z/EntryTest.php new file mode 100644 index 0000000..fc05910 --- /dev/null +++ b/Tests/Archive7z/EntryTest.php @@ -0,0 +1,10 @@ +assertInstanceOf('Exception', new Exception); + } +} diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index fffde45..3ea1bf8 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,2 +1,6 @@ add('Archive7z', array($baseDir.'/src/', $baseDir.'/Tests/')); +$loader->register(); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ff8ba93 --- /dev/null +++ b/composer.json @@ -0,0 +1,18 @@ +{ + "name": "gemorroj/archive7z", + "description": "7z cli wrapper", + "keywords": ["7z","archive"], + "type": "library", + "license": "GPLv3", + "authors": [ + { + "name": "Gemorroj" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-0": { "Archive7z\\": "src/" } + } +} \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index dbd4ae7..4b313ec 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ - + Tests diff --git a/Archive/7z.php b/src/Archive7z/Archive7z.php similarity index 84% rename from Archive/7z.php rename to src/Archive7z/Archive7z.php index d91051c..8683ea8 100644 --- a/Archive/7z.php +++ b/src/Archive7z/Archive7z.php @@ -4,17 +4,16 @@ * This software is distributed under the GNU GPL v3.0 license. * * @author Gemorroj - * @copyright 2012 http://wapinet.ru + * @copyright 2013 http://wapinet.ru * @license http://www.gnu.org/licenses/gpl-3.0.txt - * @link https://github.com/Gemorroj/Archive_7z - * @version 0.1 alpha + * @link https://github.com/Gemorroj/Archive7z + * @version 0.2 alpha * */ -require_once 'Archive/7z/Exception.php'; -require_once 'Archive/7z/Entry.php'; +namespace Archive7z; -class Archive_7z +class Archive7z { /** * Error codes @@ -93,7 +92,7 @@ class Archive_7z * @param string $filename 7z archive filename * @param string $cli CLI path * - * @throws Archive_7z_Exception + * @throws Exception */ public function __construct($filename, $cli = null) { @@ -132,15 +131,15 @@ public function getCli() /** * @param string $path * - * @throws Archive_7z_Exception - * @return Archive_7z + * @throws Exception + * @return Archive7z */ public function setCli($path) { $this->cli = realpath($path); if (is_executable($this->cli) === false) { - throw new Archive_7z_Exception('Cli is not available'); + throw new Exception('Cli is not available'); } return $this; @@ -157,8 +156,8 @@ public function getFilename() /** * @param string $filename * - * @throws Archive_7z_Exception - * @return Archive_7z + * @throws Exception + * @return Archive7z */ public function setFilename($filename) { @@ -166,7 +165,7 @@ public function setFilename($filename) $this->filename = $filename; //if (is_readable($this->filename) === false) { - // throw new Archive_7z_Exception('Filename is not available'); + // throw new Exception('Filename is not available'); //} return $this; @@ -183,15 +182,15 @@ public function getOutputDirectory() /** * @param string $directory * - * @throws Archive_7z_Exception - * @return Archive_7z + * @throws Exception + * @return Archive7z */ public function setOutputDirectory($directory = './') { $this->outputDirectory = realpath($directory); if (is_writable($this->outputDirectory) === false) { - throw new Archive_7z_Exception('Output directory is not available'); + throw new Exception('Output directory is not available'); } return $this; @@ -208,8 +207,8 @@ public function getPassword() /** * @param string $password * - * @throws Archive_7z_Exception - * @return Archive_7z + * @throws Exception + * @return Archive7z */ public function setPassword($password) { @@ -229,10 +228,10 @@ public function getOverwriteMode() /** * @param string $mode * - * @throws Archive_7z_Exception - * @return Archive_7z + * @throws Exception + * @return Archive7z */ - public function setOverwriteMode($mode = Archive_7z::OVERWRITE_MODE_A) + public function setOverwriteMode($mode = Archive7z::OVERWRITE_MODE_A) { $this->overwriteMode = $mode; @@ -245,14 +244,14 @@ public function setOverwriteMode($mode = Archive_7z::OVERWRITE_MODE_A) ) ) === false ) { - throw new Archive_7z_Exception('Overwrite mode is not available'); + throw new Exception('Overwrite mode is not available'); } return $this; } /** - * @throws Archive_7z_Exception + * @throws Exception */ public function extract() { @@ -263,7 +262,7 @@ public function extract() exec($cmd, $out, $rv); if ($rv !== 0) { - throw new Archive_7z_Exception(end($out), $rv); + throw new Exception(end($out), $rv); } } @@ -308,7 +307,7 @@ private function getCmdPostfixCompress() /** * @param string $file * - * @throws Archive_7z_Exception + * @throws Exception */ public function extractEntry($file) { @@ -321,14 +320,14 @@ public function extractEntry($file) exec($cmd, $out, $rv); if ($rv !== 0) { - throw new Archive_7z_Exception(end($out), $rv); + throw new Exception(end($out), $rv); } } /** * @param string $file * - * @throws Archive_7z_Exception + * @throws Exception * @return string */ public function getContent($file) @@ -340,7 +339,7 @@ public function getContent($file) $result = shell_exec($cmd); if ($result === null) { - throw new Archive_7z_Exception('Error'); + throw new Exception('Error'); } return $result; @@ -348,8 +347,8 @@ public function getContent($file) /** * @param string $file - * @throws Archive_7z_Exception - * @return Archive_7z_Entry|null + * @throws Exception + * @return Entry|null */ public function getEntry($file) { @@ -365,8 +364,8 @@ public function getEntry($file) } /** - * @throws Archive_7z_Exception - * @return Archive_7z_Entry[] + * @throws Exception + * @return Entry[] */ public function getEntries() { @@ -375,12 +374,12 @@ public function getEntries() exec($cmd, $out, $rv); if ($rv !== 0) { - throw new Archive_7z_Exception(end($out), $rv); + throw new Exception(end($out), $rv); } $list = array(); foreach ($this->parseEntries($out) as $v) { - $list[] = new Archive_7z_Entry($this, $v); + $list[] = new Entry($this, $v); } return $list; @@ -425,7 +424,7 @@ private function parseEntries(array $output) * @param bool $includeSubFiles * @param bool $storePath * - * @throws Archive_7z_Exception + * @throws Exception */ public function addEntry($file, $includeSubFiles = false, $storePath = false) { @@ -447,14 +446,14 @@ public function addEntry($file, $includeSubFiles = false, $storePath = false) exec($cmd, $out, $rv); if ($rv !== 0) { - throw new Archive_7z_Exception(end($out), $rv); + throw new Exception(end($out), $rv); } } /** * @param string $file * - * @throws Archive_7z_Exception + * @throws Exception */ public function delEntry($file) { @@ -464,7 +463,7 @@ public function delEntry($file) exec($cmd, $out, $rv); if ($rv !== 0) { - throw new Archive_7z_Exception(end($out), $rv); + throw new Exception(end($out), $rv); } } @@ -474,7 +473,7 @@ public function delEntry($file) * @param string $fileSrc * @param string $fileDest * - * @throws Archive_7z_Exception + * @throws Exception */ public function renameEntry($fileSrc, $fileDest) { @@ -484,7 +483,7 @@ public function renameEntry($fileSrc, $fileDest) exec($cmd, $out, $rv); if ($rv !== 0) { - throw new Archive_7z_Exception(end($out), $rv); + throw new Exception(end($out), $rv); } } } diff --git a/Archive/7z/Entry.php b/src/Archive7z/Entry.php similarity index 91% rename from Archive/7z/Entry.php rename to src/Archive7z/Entry.php index 8cf6a86..ef0c451 100644 --- a/Archive/7z/Entry.php +++ b/src/Archive7z/Entry.php @@ -4,14 +4,16 @@ * This software is distributed under the GNU GPL v3.0 license. * * @author Gemorroj - * @copyright 2012 http://wapinet.ru + * @copyright 2013 http://wapinet.ru * @license http://www.gnu.org/licenses/gpl-3.0.txt - * @link https://github.com/Gemorroj/Archive_7z - * @version 0.1 alpha + * @link https://github.com/Gemorroj/Archive7z + * @version 0.2 alpha * */ -class Archive_7z_Entry +namespace Archive7z; + +class Entry { /** * @var string @@ -51,16 +53,16 @@ class Archive_7z_Entry private $block; /** - * @var Archive_7z + * @var Archive7z */ private $archive; /** - * @param Archive_7z $archive + * @param Archive7z $archive * @param array $data */ - public function __construct(Archive_7z $archive, array $data) + public function __construct(Archive7z $archive, array $data) { $this->archive = $archive; $this->parseEntry($data); @@ -147,7 +149,7 @@ public function isEncrypted() /** - * @throws Archive_7z_Exception + * @throws Exception * @return string */ public function getContent() @@ -157,7 +159,7 @@ public function getContent() /** - * @throws Archive_7z_Exception + * @throws Exception */ public function extract() { @@ -168,7 +170,7 @@ public function extract() /** * @param string $directory * - * @throws Archive_7z_Exception + * @throws Exception */ public function extractTo($directory = './') { diff --git a/Archive/7z/Exception.php b/src/Archive7z/Exception.php similarity index 50% rename from Archive/7z/Exception.php rename to src/Archive7z/Exception.php index 867d4db..b29a2c9 100644 --- a/Archive/7z/Exception.php +++ b/src/Archive7z/Exception.php @@ -4,14 +4,16 @@ * This software is distributed under the GNU GPL v3.0 license. * * @author Gemorroj - * @copyright 2012 http://wapinet.ru + * @copyright 2013 http://wapinet.ru * @license http://www.gnu.org/licenses/gpl-3.0.txt - * @link https://github.com/Gemorroj/Archive_7z - * @version 0.1 alpha + * @link https://github.com/Gemorroj/Archive7z + * @version 0.2 alpha * */ -class Archive_7z_Exception extends Exception +namespace Archive7z; + +class Exception extends \Exception { }