Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
60
core/lib/Drupal/Core/Archiver/Annotation/Archiver.php
Normal file
60
core/lib/Drupal/Core/Archiver/Annotation/Archiver.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Archiver\Annotation\Archiver.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Archiver\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines an archiver annotation object.
|
||||
*
|
||||
* Plugin Namespace: Plugin\Archiver
|
||||
*
|
||||
* For a working example, see \Drupal\system\Plugin\Archiver\Zip
|
||||
*
|
||||
* @see \Drupal\Core\Archiver\ArchiverManager
|
||||
* @see \Drupal\Core\Archiver\ArchiverInterface
|
||||
* @see plugin_api
|
||||
* @see hook_archiver_info_alter()
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class Archiver extends Plugin {
|
||||
|
||||
/**
|
||||
* The archiver plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The human-readable name of the archiver plugin.
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* The description of the archiver plugin.
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* An array of valid extensions for this archiver.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $extensions;
|
||||
|
||||
}
|
1894
core/lib/Drupal/Core/Archiver/ArchiveTar.php
Normal file
1894
core/lib/Drupal/Core/Archiver/ArchiveTar.php
Normal file
File diff suppressed because it is too large
Load diff
14
core/lib/Drupal/Core/Archiver/ArchiverException.php
Normal file
14
core/lib/Drupal/Core/Archiver/ArchiverException.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Archiver\ArchiverException.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Archiver;
|
||||
|
||||
/**
|
||||
* Defines an exception class for Drupal\Core\Archiver\ArchiverInterface.
|
||||
*/
|
||||
class ArchiverException extends \Exception {}
|
||||
|
64
core/lib/Drupal/Core/Archiver/ArchiverInterface.php
Normal file
64
core/lib/Drupal/Core/Archiver/ArchiverInterface.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Archiver\ArchiverInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Archiver;
|
||||
|
||||
/**
|
||||
* Defines the common interface for all Archiver classes.
|
||||
*
|
||||
* @see \Drupal\Core\Archiver\ArchiverManager
|
||||
* @see \Drupal\Core\Archiver\Annotation\Archiver
|
||||
* @see plugin_api
|
||||
*/
|
||||
interface ArchiverInterface {
|
||||
|
||||
/**
|
||||
* Adds the specified file or directory to the archive.
|
||||
*
|
||||
* @param string $file_path
|
||||
* The full system path of the file or directory to add. Only local files
|
||||
* and directories are supported.
|
||||
*
|
||||
* @return \Drupal\Core\Archiver\ArchiverInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function add($file_path);
|
||||
|
||||
/**
|
||||
* Removes the specified file from the archive.
|
||||
*
|
||||
* @param string $path
|
||||
* The file name relative to the root of the archive to remove.
|
||||
*
|
||||
* @return \Drupal\Core\Archiver\ArchiverInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function remove($path);
|
||||
|
||||
/**
|
||||
* Extracts multiple files in the archive to the specified path.
|
||||
*
|
||||
* @param string $path
|
||||
* A full system path of the directory to which to extract files.
|
||||
* @param array $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 \Drupal\Core\Archiver\ArchiverInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function extract($path, array $files = array());
|
||||
|
||||
/**
|
||||
* Lists all files in the archive.
|
||||
*
|
||||
* @return array
|
||||
* An array of file names relative to the root of the archive.
|
||||
*/
|
||||
public function listContents();
|
||||
}
|
69
core/lib/Drupal/Core/Archiver/ArchiverManager.php
Normal file
69
core/lib/Drupal/Core/Archiver/ArchiverManager.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Archiver\ArchiverManager.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Archiver;
|
||||
|
||||
use Drupal\Component\Plugin\Factory\DefaultFactory;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
||||
/**
|
||||
* Provides an Archiver plugin manager.
|
||||
*
|
||||
* @see \Drupal\Core\Archiver\Annotation\Archiver
|
||||
* @see \Drupal\Core\Archiver\ArchiverInterface
|
||||
* @see plugin_api
|
||||
*/
|
||||
class ArchiverManager extends DefaultPluginManager {
|
||||
|
||||
/**
|
||||
* Constructs a ArchiverManager object.
|
||||
*
|
||||
* @param \Traversable $namespaces
|
||||
* An object that implements \Traversable which contains the root paths
|
||||
* keyed by the corresponding namespace to look for plugin implementations.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* Cache backend instance to use.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler to invoke the alter hook with.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\ArchiverInterface', 'Drupal\Core\Archiver\Annotation\Archiver');
|
||||
$this->alterInfo('archiver_info');
|
||||
$this->setCacheBackend($cache_backend, 'archiver_info_plugins');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance().
|
||||
*/
|
||||
public function createInstance($plugin_id, array $configuration = array()) {
|
||||
$plugin_definition = $this->getDefinition($plugin_id);
|
||||
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition, 'Drupal\Core\Archiver\ArchiverInterface');
|
||||
return new $plugin_class($configuration['filepath']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\PluginManagerInterface::getInstance().
|
||||
*/
|
||||
public function getInstance(array $options) {
|
||||
$filepath = $options['filepath'];
|
||||
foreach ($this->getDefinitions() as $plugin_id => $definition) {
|
||||
foreach ($definition['extensions'] as $extension) {
|
||||
// Because extensions may be multi-part, such as .tar.gz,
|
||||
// we cannot use simpler approaches like substr() or pathinfo().
|
||||
// This method isn't quite as clean but gets the job done.
|
||||
// Also note that the file may not yet exist, so we cannot rely
|
||||
// on fileinfo() or other disk-level utilities.
|
||||
if (strrpos($filepath, '.' . $extension) === strlen($filepath) - strlen('.' . $extension)) {
|
||||
return $this->createInstance($plugin_id, $options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
95
core/lib/Drupal/Core/Archiver/Tar.php
Normal file
95
core/lib/Drupal/Core/Archiver/Tar.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Archiver\Tar.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Archiver;
|
||||
|
||||
/**
|
||||
* Defines a archiver implementation for .tar files.
|
||||
*/
|
||||
class Tar implements ArchiverInterface {
|
||||
|
||||
/**
|
||||
* The underlying ArchiveTar instance that does the heavy lifting.
|
||||
*
|
||||
* @var \Drupal\Core\Archiver\ArchiveTar
|
||||
*/
|
||||
protected $tar;
|
||||
|
||||
/**
|
||||
* Constructs a Tar object.
|
||||
*
|
||||
* @param string $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.
|
||||
*
|
||||
* @throws \Drupal\Core\Archiver\ArchiverException
|
||||
*/
|
||||
public function __construct($file_path) {
|
||||
$this->tar = new ArchiveTar($file_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($file_path) {
|
||||
$this->tar->add($file_path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function extract($path, array $files = array()) {
|
||||
if ($files) {
|
||||
$this->tar->extractList($files, $path);
|
||||
}
|
||||
else {
|
||||
$this->tar->extract($path);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listContents() {
|
||||
$files = array();
|
||||
foreach ($this->tar->listContent() as $file_data) {
|
||||
$files[] = $file_data['filename'];
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves 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 Archive_Tar
|
||||
* The Archive_Tar object used by this object.
|
||||
*/
|
||||
public function getArchive() {
|
||||
return $this->tar;
|
||||
}
|
||||
}
|
97
core/lib/Drupal/Core/Archiver/Zip.php
Normal file
97
core/lib/Drupal/Core/Archiver/Zip.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Archiver\Zip.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Archiver;
|
||||
|
||||
/**
|
||||
* Defines a archiver implementation for .zip files.
|
||||
*
|
||||
* @link http://php.net/zip
|
||||
*/
|
||||
class Zip implements ArchiverInterface {
|
||||
|
||||
/**
|
||||
* The underlying ZipArchive instance that does the heavy lifting.
|
||||
*
|
||||
* @var \ZipArchive
|
||||
*/
|
||||
protected $zip;
|
||||
|
||||
/**
|
||||
* Constructs a Zip object.
|
||||
*
|
||||
* @param string $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.
|
||||
*
|
||||
* @throws \Drupal\Core\Archiver\ArchiverException
|
||||
*/
|
||||
public function __construct($file_path) {
|
||||
$this->zip = new \ZipArchive();
|
||||
if ($this->zip->open($file_path) !== TRUE) {
|
||||
throw new ArchiverException(t('Cannot open %file_path', array('%file_path' => $file_path)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($file_path) {
|
||||
$this->zip->addFile($file_path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function remove($file_path) {
|
||||
$this->zip->deleteName($file_path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function extract($path, Array $files = array()) {
|
||||
if ($files) {
|
||||
$this->zip->extractTo($path, $files);
|
||||
}
|
||||
else {
|
||||
$this->zip->extractTo($path);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listContents() {
|
||||
$files = array();
|
||||
for ($i=0; $i < $this->zip->numFiles; $i++) {
|
||||
$files[] = $this->zip->getNameIndex($i);
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves 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 \ZipArchive
|
||||
* The ZipArchive object used by this object.
|
||||
*/
|
||||
public function getArchive() {
|
||||
return $this->zip;
|
||||
}
|
||||
}
|
Reference in a new issue