Cli
1 year ago
Exporters
1 year ago
Importers
1 year ago
ResourceStorages
1 year ago
ResultFormatters
1 year ago
Schemas
1 year ago
Steps
1 year ago
docs
1 year ago
BuiltInExporters.php
1 year ago
BuiltInStepProcessors.php
1 year ago
ClassExtractor.php
1 year ago
Cli.php
1 year ago
ExportSchema.php
1 year ago
ImportSchema.php
1 year ago
ImportStep.php
1 year ago
Logger.php
1 year ago
ResourceStorages.php
1 year ago
StepProcessor.php
1 year ago
StepProcessorResult.php
1 year ago
UsePluginHelpers.php
1 year ago
UsePubSub.php
1 year ago
UseWPFunctions.php
1 year ago
Util.php
1 year ago
ResourceStorages.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blueprint; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blueprint\ResourceStorages\ResourceStorage; |
| 6 | |
| 7 | /** |
| 8 | * Class ResourceStorages |
| 9 | */ |
| 10 | class ResourceStorages { |
| 11 | /** |
| 12 | * Storage collection. |
| 13 | * |
| 14 | * @var ResourceStorages[] |
| 15 | */ |
| 16 | protected array $storages = array(); |
| 17 | |
| 18 | /** |
| 19 | * Add a downloader. |
| 20 | * |
| 21 | * @param ResourceStorage $downloader The downloader to add. |
| 22 | * |
| 23 | * @return void |
| 24 | */ |
| 25 | public function add_storage( ResourceStorage $downloader ) { |
| 26 | $supported_resource = $downloader->get_supported_resource(); |
| 27 | if ( ! isset( $this->storages[ $supported_resource ] ) ) { |
| 28 | $this->storages[ $supported_resource ] = array(); |
| 29 | } |
| 30 | $this->storages[ $supported_resource ][] = $downloader; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Check if the resource is supported. |
| 35 | * |
| 36 | * @param string $resource_type The resource type to check. |
| 37 | * |
| 38 | * @return bool |
| 39 | */ |
| 40 | public function is_supported_resource( $resource_type ) { |
| 41 | return isset( $this->storages[ $resource_type ] ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Download the resource. |
| 46 | * |
| 47 | * @param string $slug The slug of the resource to download. |
| 48 | * @param string $resource_type The resource type to download. |
| 49 | * |
| 50 | * @return false|string |
| 51 | */ |
| 52 | public function download( $slug, $resource_type ) { |
| 53 | if ( ! isset( $this->storages[ $resource_type ] ) ) { |
| 54 | return false; |
| 55 | } |
| 56 | $storages = $this->storages[ $resource_type ]; |
| 57 | foreach ( $storages as $storage ) { |
| 58 | $found = $storage->download( $slug ); |
| 59 | if ( $found ) { |
| 60 | return $found; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return false; |
| 65 | } |
| 66 | } |
| 67 |