-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.php
More file actions
49 lines (39 loc) · 1.41 KB
/
bootstrap.php
File metadata and controls
49 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Syde\PayPal\PointOfSale;
use Dhii\Container\CachingContainer;
use Dhii\Container\CompositeCachingServiceProvider;
use Dhii\Container\DelegatingContainer;
use Dhii\Container\ProxyContainer;
use Dhii\Modular\Module\ModuleInterface;
use Dhii\Validation\ValidatorInterface;
use Psr\Container\ContainerInterface;
return static function (string $appDir, bool $validate = false): ContainerInterface {
$modules = [];
$classNames = require $appDir . '/modules.php';
array_walk(
$classNames,
static function (string $className) use (&$modules): void {
$modules[] = new $className();
}
);
$providers = [];
foreach ($modules as $module) {
assert($module instanceof ModuleInterface);
$providers[] = $module->setup();
}
$proxy = new ProxyContainer();
$provider = new CompositeCachingServiceProvider($providers);
$container = new CachingContainer(new DelegatingContainer($provider, $proxy));
$proxy->setInnerContainer($container);
if ($validate) {
$requirementsValidator = $container->get('paypal-pos.requirements.validator');
assert($requirementsValidator instanceof ValidatorInterface);
$requirementsValidator->validate(null);
}
foreach ($modules as $module) {
assert($module instanceof ModuleInterface);
$module->run($proxy);
}
return $proxy;
};