Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pear coding style, add markdown readme

  • Loading branch information...
commit 1e4292865956e9eafd4b80ec1fd5faddee17624e 1 parent d2f210c
Gemorroj authored
50 Archive/7z.php
View
@@ -2,11 +2,12 @@
/**
*
* This software is distributed under the GNU GPL v3.0 license.
- * @author Gemorroj
+ *
+ * @author Gemorroj
* @copyright 2012 http://wapinet.ru
- * @license http://www.gnu.org/licenses/gpl-3.0.txt
- * @link http://wapinet.ru/gmanager/
- * @version 0.1 alpha
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ * @link http://wapinet.ru/gmanager/
+ * @version 0.1 alpha
*
*/
@@ -62,16 +63,20 @@ class Archive_7z
/**
* @param string $filename 7z archive filename
+ *
* @throws Archive_7z_Exception
*/
public function __construct($filename)
{
- $this->setFilename($filename)->setCmdPath(substr(PHP_OS, 0, 3) === 'WIN' ? self::CMD_PATH_WIN : self::CMD_PATH_NIX);
+ $this->setFilename($filename)->setCmdPath(
+ substr(PHP_OS, 0, 3) === 'WIN' ? self::CMD_PATH_WIN : self::CMD_PATH_NIX
+ );
}
/**
* @param string $path
+ *
* @throws Archive_7z_Exception
* @return Archive_7z
*/
@@ -89,6 +94,7 @@ public function setCmdPath($path)
/**
* @param string $filename
+ *
* @throws Archive_7z_Exception
* @return Archive_7z
*/
@@ -106,6 +112,7 @@ public function setFilename($filename)
/**
* @param string $directory
+ *
* @throws Archive_7z_Exception
* @return Archive_7z
*/
@@ -123,6 +130,7 @@ public function setOutputDirectory($directory = './')
/**
* @param string $password
+ *
* @throws Archive_7z_Exception
* @return Archive_7z
*/
@@ -136,6 +144,7 @@ public function setPassword($password)
/**
* @param string $mode
+ *
* @throws Archive_7z_Exception
* @return Archive_7z
*/
@@ -143,12 +152,14 @@ public function setOverwriteMode($mode = Archive_7z::OVERWRITE_MODE_A)
{
$this->_overwriteMode = $mode;
- if (in_array($this->_overwriteMode, array(
- self::OVERWRITE_MODE_A,
- self::OVERWRITE_MODE_S,
- self::OVERWRITE_MODE_T,
- self::OVERWRITE_MODE_U
- )) === false
+ if (in_array(
+ $this->_overwriteMode, array(
+ self::OVERWRITE_MODE_A,
+ self::OVERWRITE_MODE_S,
+ self::OVERWRITE_MODE_T,
+ self::OVERWRITE_MODE_U
+ )
+ ) === false
) {
throw new Archive_7z_Exception('Overwrite mode is not available');
}
@@ -220,6 +231,7 @@ private function _getCmdPostfix()
if ($this->_password !== null) {
$cmd .= ' -p' . escapeshellarg($this->_password);
}
+
return $cmd;
}
@@ -229,7 +241,9 @@ private function _getCmdPostfix()
*/
public function extract()
{
- $cmd = $this->_getCmdPrefix() . ' x ' . escapeshellarg($this->_filename) . ' ' . escapeshellcmd($this->_overwriteMode) . ' -o' . escapeshellarg($this->_outputDirectory) . ' ' . $this->_getCmdPostfix();
+ $cmd = $this->_getCmdPrefix() . ' x ' . escapeshellarg($this->_filename) . ' ' . escapeshellcmd(
+ $this->_overwriteMode
+ ) . ' -o' . escapeshellarg($this->_outputDirectory) . ' ' . $this->_getCmdPostfix();
exec($cmd, $out, $rv);
@@ -241,11 +255,16 @@ public function extract()
/**
* @param string $file
+ *
* @throws Archive_7z_Exception
*/
public function extractEntry($file)
{
- $cmd = $this->_getCmdPrefix() . ' x ' . escapeshellarg($this->_filename) . ' ' . escapeshellcmd($this->_overwriteMode) . ' -o' . escapeshellarg($this->_outputDirectory) . ' ' . $this->_getCmdPostfix() . ' ' . escapeshellarg($file);
+ $cmd = $this->_getCmdPrefix() . ' x ' . escapeshellarg($this->_filename) . ' ' . escapeshellcmd(
+ $this->_overwriteMode
+ ) . ' -o' . escapeshellarg($this->_outputDirectory) . ' ' . $this->_getCmdPostfix() . ' ' . escapeshellarg(
+ $file
+ );
exec($cmd, $out, $rv);
@@ -257,12 +276,14 @@ public function extractEntry($file)
/**
* @param string $file
+ *
* @throws Archive_7z_Exception
* @return string
*/
public function getContent($file)
{
- $cmd = $this->_getCmdPrefix() . ' x ' . escapeshellarg($this->_filename) . ' -so ' . escapeshellarg($file) . ' ' . $this->_getCmdPostfix();
+ $cmd = $this->_getCmdPrefix() . ' x ' . escapeshellarg($this->_filename) . ' -so ' . escapeshellarg($file) . ' '
+ . $this->_getCmdPostfix();
$out = shell_exec($cmd);
@@ -299,6 +320,7 @@ public function getEntries()
/**
* @param array $output
+ *
* @return array
*/
private function _parseEntries(array $output)
66 Archive/7z/Entry.php
View
@@ -2,11 +2,12 @@
/**
*
* This software is distributed under the GNU GPL v3.0 license.
- * @author Gemorroj
+ *
+ * @author Gemorroj
* @copyright 2012 http://wapinet.ru
- * @license http://www.gnu.org/licenses/gpl-3.0.txt
- * @link http://wapinet.ru/gmanager/
- * @version 0.1 alpha
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ * @link http://wapinet.ru/gmanager/
+ * @version 0.1 alpha
*
*/
@@ -57,7 +58,7 @@ class Archive_7z_Entry
/**
* @param Archive_7z $archive
- * @param array $data
+ * @param array $data
*/
public function __construct(Archive_7z $archive, array $data)
{
@@ -87,41 +88,41 @@ private function _parseEntry(array $data)
private function _setData($key, $value)
{
switch ($key) {
- case 'Path':
- $this->_path = $value;
- break;
+ case 'Path':
+ $this->_path = $value;
+ break;
- case 'Size':
- $this->_size = $value;
- break;
+ case 'Size':
+ $this->_size = $value;
+ break;
- case 'Packed Size':
- $this->_packedSize = $value;
- break;
+ case 'Packed Size':
+ $this->_packedSize = $value;
+ break;
- case 'Modified':
- $this->_modified = $value;
- break;
+ case 'Modified':
+ $this->_modified = $value;
+ break;
- case 'Attributes':
- $this->_attributes = $value;
- break;
+ case 'Attributes':
+ $this->_attributes = $value;
+ break;
- case 'CRC':
- $this->_crc = $value;
- break;
+ case 'CRC':
+ $this->_crc = $value;
+ break;
- case 'Encrypted':
- $this->_encrypted = $value;
- break;
+ case 'Encrypted':
+ $this->_encrypted = $value;
+ break;
- case 'Method':
- $this->_method = $value;
- break;
+ case 'Method':
+ $this->_method = $value;
+ break;
- case 'Block':
- $this->_block = $value;
- break;
+ case 'Block':
+ $this->_block = $value;
+ break;
}
}
@@ -156,6 +157,7 @@ public function extract()
/**
* @param string $directory
+ *
* @throws Archive_7z_Exception
*/
public function extractTo($directory = './')
9 Archive/7z/Exception.php
View
@@ -2,11 +2,12 @@
/**
*
* This software is distributed under the GNU GPL v3.0 license.
- * @author Gemorroj
+ *
+ * @author Gemorroj
* @copyright 2012 http://wapinet.ru
- * @license http://www.gnu.org/licenses/gpl-3.0.txt
- * @link http://wapinet.ru/gmanager/
- * @version 0.1 alpha
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ * @link http://wapinet.ru/gmanager/
+ * @version 0.1 alpha
*
*/
27 README.md
View
@@ -0,0 +1,27 @@
+# Работа с 7z архивами с помощью командной строки.
+
+На данный момент, поддерживается распаковка всего архива,
+распаковка любой директории или файла в архиве,
+просмотр всех файлов и директорий находящихся в архиве,
+получение содержимого файла в архиве.
+
+Пример:
+```php
+<?php
+set_include_path(__DIR__);
+require 'Archive/7z.php';
+
+$obj = new Archive_7z('./test.7z');
+$obj->setOutputDirectory('./test');
+
+foreach ($obj->getEntries() as $v) {
+ if ($v->getName() === 'test.txt') {
+ print_r($v);
+ $v->extractTo('./test2');
+ }
+}
+
+echo $obj->getContent('test.txt');
+
+$obj->extract();
+```
Please sign in to comment.
Something went wrong with that request. Please try again.