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 Container $app |
45
|
|
|
*/ |
46
|
|
|
private function registerConfig(Container $app): void |
47
|
|
|
{ |
48
|
|
|
$app->bindInjector(DistributionConfig::class, ConfiguratorInterface::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param Container $app |
53
|
|
|
*/ |
54
|
|
|
private function registerResolver(Container $app): void |
55
|
|
|
{ |
56
|
|
|
$app->bindSingleton(ResolverInterface::class, static function (ManagerInterface $manager) { |
57
|
|
|
return $manager->resolver(); |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
$app->bindSingleton(Resolver::class, static function (Container $app) { |
61
|
|
|
return $app->get(ResolverInterface::class); |
62
|
|
|
}); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param Container $app |
67
|
|
|
*/ |
68
|
|
|
private function registerManager(Container $app): void |
69
|
|
|
{ |
70
|
|
|
$app->bindSingleton(ManagerInterface::class, static function (DistributionConfig $config) { |
71
|
|
|
$manager = new Manager($config->getDefaultDriver()); |
72
|
|
|
|
73
|
|
|
foreach ($config->getResolvers() as $name => $resolver) { |
74
|
|
|
$manager->add($name, $resolver); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $manager; |
78
|
|
|
}); |
79
|
|
|
|
80
|
|
|
$app->bindSingleton(MutableManagerInterface::class, static function (Container $app) { |
81
|
|
|
return $app->get(ManagerInterface::class); |
82
|
|
|
}); |
83
|
|
|
|
84
|
|
|
$app->bindSingleton(Manager::class, static function (Container $app) { |
85
|
|
|
return $app->get(ManagerInterface::class); |
86
|
|
|
}); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.