1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Spiral Framework. |
5
|
|
|
* |
6
|
|
|
* @license MIT |
7
|
|
|
* @author Anton Titov (Wolfy-J) |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Spiral\Bootloader\Storage; |
13
|
|
|
|
14
|
|
|
use Spiral\Boot\Bootloader\Bootloader; |
15
|
|
|
use Spiral\Config\ConfiguratorInterface; |
16
|
|
|
use Spiral\Core\Container; |
17
|
|
|
use Spiral\Core\Exception\InvalidArgumentException; |
18
|
|
|
use Spiral\Storage\Manager; |
19
|
|
|
use Spiral\Storage\ManagerInterface; |
20
|
|
|
use Spiral\Storage\Storage; |
21
|
|
|
use Spiral\Storage\StorageInterface; |
22
|
|
|
use Spiral\Distribution\ManagerInterface as CdnInterface; |
23
|
|
|
|
24
|
|
|
class StorageBootloader extends Bootloader |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param Container $app |
28
|
|
|
* @param ConfiguratorInterface $config |
29
|
|
|
*/ |
30
|
|
|
public function boot(Container $app, ConfiguratorInterface $config): void |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$app->bindInjector(StorageConfig::class, ConfiguratorInterface::class); |
33
|
|
|
|
34
|
|
|
$app->bindSingleton(ManagerInterface::class, static function (StorageConfig $config, CdnInterface $cdn) { |
35
|
|
|
$manager = new Manager($config->getDefaultBucket()); |
36
|
|
|
|
37
|
|
|
$distributions = $config->getDistributions(); |
38
|
|
|
|
39
|
|
|
foreach ($config->getAdapters() as $name => $adapter) { |
40
|
|
|
$resolver = isset($distributions[$name]) |
41
|
|
|
? $cdn->resolver($distributions[$name]) |
42
|
|
|
: null; |
43
|
|
|
|
44
|
|
|
$manager->add($name, Storage::fromAdapter($adapter, $resolver)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $manager; |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
$app->bindSingleton(Manager::class, static function (ManagerInterface $manager) { |
51
|
|
|
return $manager; |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$app->bindSingleton(StorageInterface::class, static function (ManagerInterface $manager) { |
55
|
|
|
return $manager->storage(); |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
$app->bindSingleton(Storage::class, static function (StorageInterface $storage) { |
59
|
|
|
return $storage; |
60
|
|
|
}); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.