LocalPluginResourceStorage.php
1 year ago
LocalThemeResourceStorage.php
1 year ago
OrgPluginResourceStorage.php
1 year ago
OrgThemeResourceStorage.php
1 year ago
ResourceStorage.php
1 year ago
LocalPluginResourceStorage.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blueprint\ResourceStorages; |
| 4 | |
| 5 | /** |
| 6 | * Class LocalPluginResourceStorage |
| 7 | */ |
| 8 | class LocalPluginResourceStorage implements ResourceStorage { |
| 9 | /** |
| 10 | * Paths to the directories containing the plugins. |
| 11 | * |
| 12 | * @var array The paths to the directories containing the plugins. |
| 13 | */ |
| 14 | protected array $paths = array(); |
| 15 | |
| 16 | /** |
| 17 | * Suffix of the plugin files. |
| 18 | * |
| 19 | * @var string The suffix of the plugin files. |
| 20 | */ |
| 21 | protected string $suffix = 'plugins'; |
| 22 | |
| 23 | /** |
| 24 | * LocalPluginResourceStorage constructor. |
| 25 | * |
| 26 | * @param string $path The path to the directory containing the plugins. |
| 27 | */ |
| 28 | public function __construct( $path ) { |
| 29 | $this->paths[] = $path; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Local plugins are already included (downloaded) in the zip file. |
| 34 | * Return the full path. |
| 35 | * |
| 36 | * @param string $slug The slug of the plugin to be downloaded. |
| 37 | * |
| 38 | * @return string|null |
| 39 | */ |
| 40 | public function download( $slug ): ?string { |
| 41 | foreach ( $this->paths as $path ) { |
| 42 | $full_path = $path . "/{$this->suffix}/" . $slug . '.zip'; |
| 43 | if ( is_file( $full_path ) ) { |
| 44 | return $full_path; |
| 45 | } |
| 46 | } |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get the supported resource. |
| 52 | * |
| 53 | * @return string The supported resource. |
| 54 | */ |
| 55 | public function get_supported_resource(): string { |
| 56 | return 'self/plugins'; |
| 57 | } |
| 58 | } |
| 59 |