|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Buttress\Concrete\Provider\LeagueContainer; |
|
4
|
|
|
|
|
5
|
|
|
use Buttress\Concrete\Client\Adapter\AdapterFactory; |
|
6
|
|
|
use Buttress\Concrete\Client\Concrete5; |
|
7
|
|
|
use Buttress\Concrete\Client\Connection\Connection; |
|
8
|
|
|
use Buttress\Concrete\Client\Connection\LegacyConnection; |
|
9
|
|
|
use Buttress\Concrete\Client\Connection\ModernConnection; |
|
10
|
|
|
use Buttress\Concrete\CommandBus\Command\HandlerLocator; |
|
11
|
|
|
use Buttress\Concrete\Client\Adapter\Adapter; |
|
12
|
|
|
use Buttress\Concrete\Client\Adapter\LegacyAdapter; |
|
13
|
|
|
use Buttress\Concrete\Client\Adapter\ModernAdapter; |
|
14
|
|
|
use Buttress\Concrete\Console\Command\Collection\Collection; |
|
15
|
|
|
use Buttress\Concrete\Console\Console; |
|
16
|
|
|
use Buttress\Concrete\Exception\ErrorHandler; |
|
17
|
|
|
use Buttress\Concrete\Locator\Locator; |
|
18
|
|
|
use Buttress\Concrete\Locator\Site; |
|
19
|
|
|
use Buttress\Concrete\Log\Logger; |
|
20
|
|
|
use Concrete\Core\Application\Application; |
|
21
|
|
|
use League\CLImate\CLImate; |
|
22
|
|
|
use League\Container\ServiceProvider\AbstractServiceProvider; |
|
23
|
|
|
use League\Container\ServiceProvider\BootableServiceProviderInterface; |
|
24
|
|
|
use League\Tactician\CommandBus; |
|
25
|
|
|
use League\Tactician\Handler\CommandHandlerMiddleware; |
|
26
|
|
|
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor; |
|
27
|
|
|
use League\Tactician\Handler\MethodNameInflector\HandleClassNameInflector; |
|
28
|
|
|
use Psr\Container\ContainerInterface; |
|
29
|
|
|
use Psr\Log\LoggerInterface; |
|
30
|
|
|
|
|
31
|
|
|
class ServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
protected $serviceProviders = [ |
|
35
|
|
|
\Buttress\Concrete\Client\ServiceProvider::class, |
|
36
|
|
|
\Buttress\Concrete\Service\Package\ServiceProvider::class |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
protected $provides = [ |
|
40
|
|
|
LoggerInterface::class, |
|
41
|
|
|
Console::class, |
|
42
|
|
|
CLImate::class, |
|
43
|
|
|
CommandBus::class, |
|
44
|
|
|
ContainerInterface::class, |
|
45
|
|
|
HandlerLocator::class, |
|
46
|
|
|
Site::class, |
|
47
|
|
|
Application::class |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
public function register() |
|
51
|
|
|
{ |
|
52
|
|
|
$container = $this->getContainer(); |
|
53
|
|
|
|
|
54
|
|
|
// Share the CLImate object |
|
55
|
|
|
$container->share(CLImate::class, function () use ($container) { |
|
56
|
|
|
return new CLImate(); |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
// Share the command bus handler locator |
|
60
|
|
|
$container->share(HandlerLocator::class)->withArgument($container); |
|
61
|
|
|
|
|
62
|
|
|
// Add the command bus |
|
63
|
|
|
$container->add( |
|
64
|
|
|
CommandBus::class, |
|
65
|
|
|
function (ClassNameExtractor $extractor, HandlerLocator $locator, HandleClassNameInflector $inflector) { |
|
66
|
|
|
$handlerMiddleware = new CommandHandlerMiddleware($extractor, $locator, $inflector); |
|
67
|
|
|
|
|
68
|
|
|
return new CommandBus([$handlerMiddleware]); |
|
69
|
|
|
} |
|
70
|
|
|
)->withArguments([ClassNameExtractor::class, HandlerLocator::class, HandleClassNameInflector::class]); |
|
71
|
|
|
|
|
72
|
|
|
// Share the console object |
|
73
|
|
|
$container->share(Console::class) |
|
74
|
|
|
->withArguments([ |
|
75
|
|
|
$container, |
|
76
|
|
|
Collection::class, |
|
77
|
|
|
Site::class, |
|
78
|
|
|
ErrorHandler::class |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
$container->share(Site::class, function () use ($container) { |
|
82
|
|
|
$site = $container->get(Locator::class)->getLocation(); |
|
83
|
|
|
if (!$site) { |
|
84
|
|
|
$site = Site::create(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $site; |
|
88
|
|
|
}); |
|
89
|
|
|
|
|
90
|
|
|
// Share the container |
|
91
|
|
|
$container->share(ContainerInterface::class, $container); |
|
92
|
|
|
|
|
93
|
|
|
// Share the logger class |
|
94
|
|
|
$container->share(LoggerInterface::class, Logger::class)->withArgument(CLImate::class); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Method will be invoked on registration of a service provider implementing |
|
99
|
|
|
* this interface. Provides ability for eager loading of Service Providers. |
|
100
|
|
|
* |
|
101
|
|
|
* @return void |
|
102
|
|
|
*/ |
|
103
|
|
|
public function boot() |
|
104
|
|
|
{ |
|
105
|
|
|
$container = $this->getContainer(); |
|
106
|
|
|
foreach ($this->serviceProviders as $provider) { |
|
107
|
|
|
$container->addServiceProvider($provider); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|