Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
58e81251
Commit
58e81251
authored
Apr 11, 2013
by
Angie Byron
Browse files
Issue
#1950726
by chx: Convert hook_archiver_info() into the New Shiny(TM).
parent
be6f421c
Changes
8
Hide whitespace changes
Inline
Side-by-side
core/core.services.yml
View file @
58e81251
...
...
@@ -144,6 +144,9 @@ services:
plugin.manager.entity
:
class
:
Drupal\Core\Entity\EntityManager
arguments
:
[
'
%container.namespaces%'
]
plugin.manager.archiver
:
class
:
Drupal\Core\Archiver\ArchiverManager
arguments
:
[
'
%container.namespaces%'
]
request
:
class
:
Symfony\Component\HttpFoundation\Request
event_dispatcher
:
...
...
core/includes/common.inc
View file @
58e81251
...
...
@@ -6523,32 +6523,6 @@ function drupal_check_incompatibility($v, $current_version) {
}
}
/**
* Retrieves a list of all available archivers.
*
* @see hook_archiver_info()
* @see hook_archiver_info_alter()
*/
function archiver_get_info() {
$archiver_info = &drupal_static(__FUNCTION__, array());
if (empty($archiver_info)) {
$cache = cache()->get('archiver_info');
if ($cache === FALSE) {
// Rebuild the cache and save it.
$archiver_info = module_invoke_all('archiver_info');
drupal_alter('archiver_info', $archiver_info);
uasort($archiver_info, 'drupal_sort_weight');
cache()->set('archiver_info', $archiver_info);
}
else {
$archiver_info = $cache->data;
}
}
return $archiver_info;
}
/**
* Returns a string of supported archive extensions.
*
...
...
@@ -6558,7 +6532,7 @@ function archiver_get_info() {
*/
function archiver_get_extensions() {
$valid_extensions = array();
foreach (
archiver_get_info
() as $archive) {
foreach (
Drupal::service('plugin.manager.archiver')->getDefinitions
() as $archive) {
foreach ($archive['extensions'] as $extension) {
foreach (explode('.', $extension) as $part) {
if (!in_array($part, $valid_extensions)) {
...
...
@@ -6588,20 +6562,7 @@ function archiver_get_archiver($file) {
if (!is_file($filepath)) {
throw new Exception(t('Archivers can only operate on local files: %file not supported', array('%file' => $file)));
}
$archiver_info = archiver_get_info();
foreach ($archiver_info as $implementation) {
foreach ($implementation['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 new $implementation['class']($filepath);
}
}
}
return Drupal::service('plugin.manager.archiver')->getInstance(array('filepath' => $filepath));
}
/**
...
...
core/lib/Drupal/Core/Archiver/ArchiverManager.php
0 → 100644
View file @
58e81251
<?php
/**
* Contains \Drupal\Core\Archiver\ArchiverManager.
*/
namespace
Drupal\Core\Archiver
;
use
Drupal\Component\Plugin\Factory\DefaultFactory
;
use
Drupal\Component\Plugin\PluginManagerBase
;
use
Drupal\Core\Plugin\Discovery\AlterDecorator
;
use
Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery
;
use
Drupal\Core\Plugin\Discovery\CacheDecorator
;
/**
* Archiver plugin manager.
*/
class
ArchiverManager
extends
PluginManagerBase
{
/**
* Constructs a ArchiverManager object.
*
* @param array $namespaces
* An array of paths keyed by its corresponding namespaces.
*/
public
function
__construct
(
array
$namespaces
)
{
$this
->
discovery
=
new
AnnotatedClassDiscovery
(
'Core'
,
'Archiver'
,
$namespaces
);
$this
->
discovery
=
new
AlterDecorator
(
$this
->
discovery
,
'archiver_info'
);
$this
->
discovery
=
new
CacheDecorator
(
$this
->
discovery
,
'archiver_info'
);
}
/**
* Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance().
*/
public
function
createInstance
(
$plugin_id
,
array
$configuration
=
array
())
{
$plugin_definition
=
$this
->
discovery
->
getDefinition
(
$plugin_id
);
$plugin_class
=
DefaultFactory
::
getPluginClass
(
$plugin_id
,
$plugin_definition
);
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
);
}
}
}
}
}
core/modules/system/lib/Drupal/system/Plugin/Core/Archiver/Tar.php
0 → 100644
View file @
58e81251
<?php
/**
* @file
* Contains \Drupal\system\Plugin\Core\Archiver\Tar.
*/
namespace
Drupal\system\Plugin\Core\Archiver
;
use
Drupal\Component\Archiver\Tar
as
BaseTar
;
use
Drupal\Component\Annotation\Plugin
;
use
Drupal\Core\Annotation\Translation
;
/**
* Defines a archiver implementation for .tar files.
*
* @Plugin(
* id = "Tar",
* title = @Translation("Tar"),
* description = @Translation("Handles .tar files."),
* extensions = {"tar", "tgz", "tar.gz", "tar.bz2"}
* )
*/
class
Tar
extends
BaseTar
{
}
core/modules/system/lib/Drupal/system/Plugin/Core/Archiver/Zip.php
0 → 100644
View file @
58e81251
<?php
/**
* @file
* Contains \Drupal\system\Plugin\Core\Archiver\Zip.
*/
namespace
Drupal\system\Plugin\Core\Archiver
;
use
Drupal\Component\Archiver\Zip
as
BaseZip
;
use
Drupal\Component\Annotation\Plugin
;
use
Drupal\Core\Annotation\Translation
;
/**
* Defines a archiver implementation for .zip files.
*
* @link http://php.net/zip
*
* @Plugin(
* id = "Zip",
* title = @Translation("Zip"),
* description = @Translation("Handles zip files."),
* extensions = {"zip"}
* )
*/
class
Zip
extends
BaseZip
{
}
core/modules/system/system.api.php
View file @
58e81251
...
...
@@ -3098,33 +3098,6 @@ function hook_file_mimetype_mapping_alter(&$mapping) {
$mapping
[
'extensions'
][
'ogg'
]
=
189
;
}
/**
* Declare archivers to the system.
*
* An archiver is a class that is able to package and unpackage one or more files
* into a single possibly compressed file. Common examples of such files are
* zip files and tar.gz files. All archiver classes must implement
* ArchiverInterface.
*
* Each entry should be keyed on a unique value, and specify three
* additional keys:
* - class: The name of the PHP class for this archiver.
* - extensions: An array of file extensions that this archiver supports.
* - weight: This optional key specifies the weight of this archiver.
* When mapping file extensions to archivers, the first archiver by
* weight found that supports the requested extension will be used.
*
* @see hook_archiver_info_alter()
*/
function
hook_archiver_info
()
{
return
array
(
'tar'
=>
array
(
'class'
=>
'Drupal\Component\Archiver\Tar'
,
'extensions'
=>
array
(
'tar'
,
'tar.gz'
,
'tar.bz2'
),
),
);
}
/**
* Alter archiver information declared by other modules.
*
...
...
core/modules/system/system.module
View file @
58e81251
...
...
@@ -3889,23 +3889,6 @@ function system_date_format_delete($date_format_id) {
}
}
/**
* Implements hook_archiver_info().
*/
function system_archiver_info() {
$archivers['tar'] = array(
'class' => 'Drupal\Component\Archiver\Tar',
'extensions' => array('tar', 'tgz', 'tar.gz', 'tar.bz2'),
);
if (function_exists('zip_open')) {
$archivers['zip'] = array(
'class' => 'Drupal\Component\Archiver\Zip',
'extensions' => array('zip'),
);
}
return $archivers;
}
/**
* Returns HTML for a confirmation form.
*
...
...
core/modules/update/tests/modules/update_test/update_test.module
View file @
58e81251
...
...
@@ -136,15 +136,15 @@ function update_test_mock_page($project_name) {
}
/**
* Implements hook_archiver_info().
* Implements hook_archiver_info
_alter
().
*/
function
update_test_archiver_info
(
)
{
return
array
(
'update_test_archiver'
=>
array
(
//
This is bogus, we only care about the extensions for now.
'class'
=>
'Drupal\Component\Archiver\UpdateTest'
,
'extensions'
=>
array
(
'update
-
test
-extension'
),
),
function
update_test_archiver_info
_alter
(
&
$definitions
)
{
// We only care about the extensions for now and the only way to add a new
// extension without a class is via alter. This definition is bogus, real
//
archivers have a class and the definition goes in the annotation of the
// class.
$definitions
[
'update
_
test
_archiver'
]
=
array
(
'extensions'
=>
array
(
'update-test-extension'
),
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment