1
<?php
2

3
declare(strict_types=1);
4

5
namespace Kreait\Firebase;
6

7
use Google\Cloud\Storage\Bucket;
8
use Google\Cloud\Storage\StorageClient;
9
use Kreait\Firebase\Exception\RuntimeException;
10

11
class Storage
12
{
13
    /** @var StorageClient */
14
    private $storageClient;
15

16
    /** @var string|null */
17
    private $defaultBucket;
18

19
    /** @var Bucket[] */
20
    private $buckets = [];
21

22
    /**
23
     * @internal
24
     */
25 12
    public function __construct(StorageClient $storageClient, ?string $defaultBucket = null)
26
    {
27 12
        $this->storageClient = $storageClient;
28 12
        $this->defaultBucket = $defaultBucket;
29
    }
30

31 3
    public function getStorageClient(): StorageClient
32
    {
33 3
        return $this->storageClient;
34
    }
35

36 12
    public function getBucket(?string $name = null): Bucket
37
    {
38 12
        $name = $name ?: $this->defaultBucket;
39

40 12
        if ($name === null) {
41 9
            throw new RuntimeException(
42 9
                'No bucket name was given and no default bucked was configured.'
43
            );
44
        }
45

46 12
        if (!\array_key_exists($name, $this->buckets)) {
47 12
            $this->buckets[$name] = $this->storageClient->bucket($name);
48
        }
49

50 12
        return $this->buckets[$name];
51
    }
52
}

Read our documentation on viewing source code .

Loading