/var/www/html_de/wp-content/plugins/woocommerce/packages/blueprint/src/ResourceStorages.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

namespace Automattic\WooCommerce\Blueprint;

use 
Automattic\WooCommerce\Blueprint\ResourceStorages\ResourceStorage;

/**
 * Class ResourceStorages
 */
class ResourceStorages {
    
/**
     * Storage collection.
     *
     * @var ResourceStorages[]
     */
    
protected array $storages = array();

    
/**
     * Add a downloader.
     *
     * @param ResourceStorage $downloader The downloader to add.
     *
     * @return void
     */
    
public function add_storageResourceStorage $downloader ) {
        
$supported_resource $downloader->get_supported_resource();
        if ( ! isset( 
$this->storages$supported_resource ] ) ) {
            
$this->storages$supported_resource ] = array();
        }
        
$this->storages$supported_resource ][] = $downloader;
    }

    
/**
     * Check if the resource is supported.
     *
     * @param string $resource_type The resource type to check.
     *
     * @return bool
     */
    
public function is_supported_resource$resource_type ) {
        return isset( 
$this->storages$resource_type ] );
    }

    
/**
     * Download the resource.
     *
     * @param string $slug The slug of the resource to download.
     * @param string $resource_type The resource type to download.
     *
     * @return false|string
     */
    
public function download$slug$resource_type ) {
        if ( ! isset( 
$this->storages$resource_type ] ) ) {
            return 
false;
        }
        
$storages $this->storages$resource_type ];
        foreach ( 
$storages as $storage ) {
            
$found $storage->download$slug );
            if ( 
$found ) {
                return 
$found;
            }
        }

        return 
false;
    }
}