- Patch #1473600 by amateescu, Berdir: Convert archiver.inc to PSR-0.
parent
eab48b5956
commit
50a8bb8523
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Shared classes and interfaces for the archiver system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the common interface for all Archiver classes.
|
||||
*/
|
||||
interface ArchiverInterface {
|
||||
|
||||
/**
|
||||
* Constructs a new archiver instance.
|
||||
*
|
||||
* @param $file_path
|
||||
* The full system path of the archive to manipulate. Only local files
|
||||
* are supported. If the file does not yet exist, it will be created if
|
||||
* appropriate.
|
||||
*/
|
||||
public function __construct($file_path);
|
||||
|
||||
/**
|
||||
* Adds the specified file or directory to the archive.
|
||||
*
|
||||
* @param $file_path
|
||||
* The full system path of the file or directory to add. Only local files
|
||||
* and directories are supported.
|
||||
*
|
||||
* @return ArchiverInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function add($file_path);
|
||||
|
||||
/**
|
||||
* Removes the specified file from the archive.
|
||||
*
|
||||
* @param $path
|
||||
* The file name relative to the root of the archive to remove.
|
||||
*
|
||||
* @return ArchiverInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function remove($path);
|
||||
|
||||
/**
|
||||
* Extracts multiple files in the archive to the specified path.
|
||||
*
|
||||
* @param $path
|
||||
* A full system path of the directory to which to extract files.
|
||||
* @param $files
|
||||
* Optionally specify a list of files to be extracted. Files are
|
||||
* relative to the root of the archive. If not specified, all files
|
||||
* in the archive will be extracted.
|
||||
*
|
||||
* @return ArchiverInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function extract($path, array $files = array());
|
||||
|
||||
/**
|
||||
* Lists all files in the archive.
|
||||
*
|
||||
* @return
|
||||
* An array of file names relative to the root of the archive.
|
||||
*/
|
||||
public function listContents();
|
||||
}
|
|
@ -3493,7 +3493,7 @@ function hook_action_info_alter(&$actions) {
|
|||
function hook_archiver_info() {
|
||||
return array(
|
||||
'tar' => array(
|
||||
'class' => 'ArchiverTar',
|
||||
'class' => 'Drupal\Component\Archiver\Tar',
|
||||
'extensions' => array('tar', 'tar.gz', 'tar.bz2'),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Archiver implementations provided by the system module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Archiver for .tar files.
|
||||
*/
|
||||
class ArchiverTar implements ArchiverInterface {
|
||||
|
||||
/**
|
||||
* The underlying Archive_Tar instance that does the heavy lifting.
|
||||
*
|
||||
* @var Archive_Tar
|
||||
*/
|
||||
protected $tar;
|
||||
|
||||
public function __construct($file_path) {
|
||||
$this->tar = new Archive_Tar($file_path);
|
||||
}
|
||||
|
||||
public function add($file_path) {
|
||||
$this->tar->add($file_path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function remove($file_path) {
|
||||
// @todo Archive_Tar doesn't have a remove operation
|
||||
// so we'll have to simulate it somehow, probably by
|
||||
// creating a new archive with everything but the removed
|
||||
// file.
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function extract($path, Array $files = array()) {
|
||||
if ($files) {
|
||||
$this->tar->extractList($files, $path);
|
||||
}
|
||||
else {
|
||||
$this->tar->extract($path);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function listContents() {
|
||||
$files = array();
|
||||
foreach ($this->tar->listContent() as $file_data) {
|
||||
$files[] = $file_data['filename'];
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the tar engine itself.
|
||||
*
|
||||
* In some cases it may be necessary to directly access the underlying
|
||||
* Archive_Tar object for implementation-specific logic. This is for advanced
|
||||
* use only as it is not shared by other implementations of ArchiveInterface.
|
||||
*
|
||||
* @return
|
||||
* The Archive_Tar object used by this object.
|
||||
*/
|
||||
public function getArchive() {
|
||||
return $this->tar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Archiver for .zip files.
|
||||
*
|
||||
* @link http://php.net/zip
|
||||
*/
|
||||
class ArchiverZip implements ArchiverInterface {
|
||||
|
||||
/**
|
||||
* The underlying ZipArchive instance that does the heavy lifting.
|
||||
*
|
||||
* @var ZipArchive
|
||||
*/
|
||||
protected $zip;
|
||||
|
||||
public function __construct($file_path) {
|
||||
$this->zip = new ZipArchive();
|
||||
if ($this->zip->open($file_path) !== TRUE) {
|
||||
// @todo: This should be an interface-specific exception some day.
|
||||
throw new Exception(t('Cannot open %file_path', array('%file_path' => $file_path)));
|
||||
}
|
||||
}
|
||||
|
||||
public function add($file_path) {
|
||||
$this->zip->addFile($file_path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function remove($file_path) {
|
||||
$this->zip->deleteName($file_path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function extract($path, Array $files = array()) {
|
||||
if ($files) {
|
||||
$this->zip->extractTo($path, $files);
|
||||
}
|
||||
else {
|
||||
$this->zip->extractTo($path);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function listContents() {
|
||||
$files = array();
|
||||
for ($i=0; $i < $this->zip->numFiles; $i++) {
|
||||
$files[] = $this->zip->getNameIndex($i);
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the zip engine itself.
|
||||
*
|
||||
* In some cases it may be necessary to directly access the underlying
|
||||
* ZipArchive object for implementation-specific logic. This is for advanced
|
||||
* use only as it is not shared by other implementations of ArchiveInterface.
|
||||
*
|
||||
* @return
|
||||
* The ZipArchive object used by this object.
|
||||
*/
|
||||
public function getArchive() {
|
||||
return $this->zip;
|
||||
}
|
||||
}
|
|
@ -3,8 +3,6 @@ description = Handles general site configuration for administrators.
|
|||
package = Core
|
||||
version = VERSION
|
||||
core = 8.x
|
||||
files[] = system.archiver.inc
|
||||
files[] = system.tar.inc
|
||||
files[] = system.test
|
||||
required = TRUE
|
||||
configure = admin/config/system
|
||||
|
|
|
@ -3948,12 +3948,12 @@ function system_date_format_delete($dfid) {
|
|||
*/
|
||||
function system_archiver_info() {
|
||||
$archivers['tar'] = array(
|
||||
'class' => 'ArchiverTar',
|
||||
'class' => 'Drupal\Component\Archiver\Tar',
|
||||
'extensions' => array('tar', 'tgz', 'tar.gz', 'tar.bz2'),
|
||||
);
|
||||
if (function_exists('zip_open')) {
|
||||
$archivers['zip'] = array(
|
||||
'class' => 'ArchiverZip',
|
||||
'class' => 'Drupal\Component\Archiver\Zip',
|
||||
'extensions' => array('zip'),
|
||||
);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -121,7 +121,7 @@ function update_test_archiver_info() {
|
|||
return array(
|
||||
'update_test_archiver' => array(
|
||||
// This is bogus, we only care about the extensions for now.
|
||||
'class' => 'ArchiverUpdateTest',
|
||||
'class' => 'Drupal\Component\Archiver\UpdateTest',
|
||||
'extensions' => array('update-test-extension'),
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue