1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Spiral Framework package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Spiral\Bootloader\Distribution; |
13
|
|
|
|
14
|
|
|
use Spiral\Boot\Bootloader\Bootloader; |
15
|
|
|
use Spiral\Bootloader\Storage\StorageConfig; |
16
|
|
|
use Spiral\Config\ConfiguratorInterface; |
17
|
|
|
use Spiral\Core\Container; |
18
|
|
|
use Spiral\Distribution\Manager; |
19
|
|
|
use Spiral\Distribution\ManagerInterface; |
20
|
|
|
use Spiral\Distribution\MutableManagerInterface; |
21
|
|
|
use Spiral\Distribution\Resolver\Resolver; |
22
|
|
|
use Spiral\Distribution\ResolverInterface; |
23
|
|
|
|
24
|
|
|
class DistributionBootloader extends Bootloader |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param ConfiguratorInterface $config |
28
|
|
|
* @param Container $app |
29
|
|
|
*/ |
30
|
|
|
public function boot(ConfiguratorInterface $config, Container $app): void |
31
|
|
|
{ |
32
|
|
|
$config->setDefaults(StorageConfig::CONFIG, [ |
33
|
|
|
'default' => Manager::DEFAULT_RESOLVER, |
34
|
|
|
'servers' => [], |
35
|
|
|
'buckets' => [], |
36
|
|
|
]); |
37
|
|
|
$this->registerConfig($config, $app); |
38
|
|
|
|
39
|
|
|
$this->registerManager($app); |
40
|
|
|
$this->registerResolver($app); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param ConfiguratorInterface $config |
45
|
|
|
* @param Container $app |
46
|
|
|
*/ |
47
|
|
|
private function registerConfig(ConfiguratorInterface $config, Container $app): void |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$app->bindInjector(DistributionConfig::class, ConfiguratorInterface::class); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Container $app |
54
|
|
|
*/ |
55
|
|
|
private function registerResolver(Container $app): void |
56
|
|
|
{ |
57
|
|
|
$app->bindSingleton(ResolverInterface::class, static function (ManagerInterface $manager) { |
58
|
|
|
return $manager->resolver(); |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
$app->bindSingleton(Resolver::class, static function (Container $app) { |
62
|
|
|
return $app->get(ResolverInterface::class); |
63
|
|
|
}); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param Container $app |
68
|
|
|
*/ |
69
|
|
|
private function registerManager(Container $app): void |
70
|
|
|
{ |
71
|
|
|
$app->bindSingleton(ManagerInterface::class, static function (DistributionConfig $config) { |
72
|
|
|
$manager = new Manager($config->getDefaultDriver()); |
73
|
|
|
|
74
|
|
|
foreach ($config->getResolvers() as $name => $resolver) { |
75
|
|
|
$manager->add($name, $resolver); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $manager; |
79
|
|
|
}); |
80
|
|
|
|
81
|
|
|
$app->bindSingleton(MutableManagerInterface::class, static function (Container $app) { |
82
|
|
|
return $app->get(ManagerInterface::class); |
83
|
|
|
}); |
84
|
|
|
|
85
|
|
|
$app->bindSingleton(Manager::class, static function (Container $app) { |
86
|
|
|
return $app->get(ManagerInterface::class); |
87
|
|
|
}); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.