Issue #3420985 by godotislate, larowlan, smustgrave, mstrelan: Convert Archiver discovery to attributes
parent
83874f2bcf
commit
4ae7f8542f
|
@ -6,7 +6,7 @@ namespace Drupal\Core\Archiver;
|
|||
* Defines the common interface for all Archiver classes.
|
||||
*
|
||||
* @see \Drupal\Core\Archiver\ArchiverManager
|
||||
* @see \Drupal\Core\Archiver\Annotation\Archiver
|
||||
* @see \Drupal\Core\Archiver\Attribute\Archiver
|
||||
* @see plugin_api
|
||||
*/
|
||||
interface ArchiverInterface {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Core\Archiver;
|
||||
|
||||
use Drupal\Component\Plugin\Factory\DefaultFactory;
|
||||
use Drupal\Core\Archiver\Attribute\Archiver;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
|
@ -11,7 +12,7 @@ use Drupal\Core\Plugin\DefaultPluginManager;
|
|||
/**
|
||||
* Provides an Archiver plugin manager.
|
||||
*
|
||||
* @see \Drupal\Core\Archiver\Annotation\Archiver
|
||||
* @see \Drupal\Core\Archiver\Attribute\Archiver
|
||||
* @see \Drupal\Core\Archiver\ArchiverInterface
|
||||
* @see plugin_api
|
||||
*/
|
||||
|
@ -38,7 +39,7 @@ class ArchiverManager extends DefaultPluginManager {
|
|||
* The file handler.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, FileSystemInterface $file_system) {
|
||||
parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\ArchiverInterface', 'Drupal\Core\Archiver\Annotation\Archiver');
|
||||
parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\ArchiverInterface', Archiver::class, 'Drupal\Core\Archiver\Annotation\Archiver');
|
||||
$this->alterInfo('archiver_info');
|
||||
$this->setCacheBackend($cache_backend, 'archiver_info_plugins');
|
||||
$this->fileSystem = $file_system;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Core\Archiver\Attribute;
|
||||
|
||||
use Drupal\Component\Plugin\Attribute\Plugin;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Defines an archiver attribute 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()
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class Archiver extends Plugin {
|
||||
|
||||
/**
|
||||
* Constructs an archiver plugin attribute object.
|
||||
*
|
||||
* @param string $id
|
||||
* The archiver plugin ID.
|
||||
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $title
|
||||
* The human-readable name of the archiver plugin.
|
||||
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
|
||||
* The description of the archiver plugin.
|
||||
* @param array $extensions
|
||||
* An array of valid extensions for this archiver.
|
||||
* @param string|null $deriver
|
||||
* (optional) The deriver class.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $id,
|
||||
public readonly ?TranslatableMarkup $title = NULL,
|
||||
public readonly ?TranslatableMarkup $description = NULL,
|
||||
public readonly array $extensions = [],
|
||||
public readonly ?string $deriver = NULL) {}
|
||||
|
||||
}
|
|
@ -2,17 +2,18 @@
|
|||
|
||||
namespace Drupal\system\Plugin\Archiver;
|
||||
|
||||
use Drupal\Core\Archiver\Attribute\Archiver;
|
||||
use Drupal\Core\Archiver\Tar as BaseTar;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Defines an archiver implementation for .tar files.
|
||||
*
|
||||
* @Archiver(
|
||||
* id = "Tar",
|
||||
* title = @Translation("Tar"),
|
||||
* description = @Translation("Handles .tar files."),
|
||||
* extensions = {"tar", "tgz", "tar.gz", "tar.bz2"}
|
||||
* )
|
||||
*/
|
||||
#[Archiver(
|
||||
id: 'Tar',
|
||||
title: new TranslatableMarkup('Tar'),
|
||||
description: new TranslatableMarkup('Handles .tar files.'),
|
||||
extensions: ['tar', 'tgz', 'tar.gz', 'tar.bz2']
|
||||
)]
|
||||
class Tar extends BaseTar {
|
||||
}
|
||||
|
|
|
@ -2,19 +2,20 @@
|
|||
|
||||
namespace Drupal\system\Plugin\Archiver;
|
||||
|
||||
use Drupal\Core\Archiver\Attribute\Archiver;
|
||||
use Drupal\Core\Archiver\Zip as BaseZip;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Defines an archiver implementation for .zip files.
|
||||
*
|
||||
* @link http://php.net/zip
|
||||
*
|
||||
* @Archiver(
|
||||
* id = "Zip",
|
||||
* title = @Translation("Zip"),
|
||||
* description = @Translation("Handles zip files."),
|
||||
* extensions = {"zip"}
|
||||
* )
|
||||
*/
|
||||
#[Archiver(
|
||||
id: 'Zip',
|
||||
title: new TranslatableMarkup('Zip'),
|
||||
description: new TranslatableMarkup('Handles zip files.'),
|
||||
extensions: ['zip']
|
||||
)]
|
||||
class Zip extends BaseZip {
|
||||
}
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
namespace Drupal\update_test\Plugin\Archiver;
|
||||
|
||||
use Drupal\Core\Archiver\ArchiverInterface;
|
||||
use Drupal\Core\Archiver\Attribute\Archiver;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Defines a test archiver implementation.
|
||||
*
|
||||
* @Archiver(
|
||||
* id = "update_test_archiver",
|
||||
* title = @Translation("Update Test Archiver"),
|
||||
* extensions = {"update-test-extension"}
|
||||
* )
|
||||
*/
|
||||
#[Archiver(
|
||||
id: 'update_test_archiver',
|
||||
title: new TranslatableMarkup('Tar'),
|
||||
description: new TranslatableMarkup('Update Test Archiver'),
|
||||
extensions: ['update-test-extension']
|
||||
)]
|
||||
class UpdateTestArchiver implements ArchiverInterface {
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue