This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContainer.php
103 lines (91 loc) · 3.99 KB
/
Container.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
declare(strict_types=1);
/**
* Copyright (c) 2018-2020 Daniel Bannert
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/narrowspark/automatic
*/
namespace Narrowspark\Automatic\Security;
use Composer\Composer;
use Composer\Config;
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\Util\RemoteFilesystem;
use Narrowspark\Automatic\Common\AbstractContainer;
use Narrowspark\Automatic\Common\Contract\Container as ContainerContract;
use Narrowspark\Automatic\Common\Downloader\Downloader;
use Narrowspark\Automatic\Common\Downloader\ParallelDownloader;
use Narrowspark\Automatic\Common\Traits\GetGenericPropertyReaderTrait;
use Narrowspark\Automatic\Security\Contract\Audit as AuditContract;
use Symfony\Component\Console\Input\InputInterface;
/**
* @internal
*/
final class Container extends AbstractContainer
{
use GetGenericPropertyReaderTrait;
/**
* Instantiate the container.
*/
public function __construct(Composer $composer, IOInterface $io)
{
$genericPropertyReader = $this->getGenericPropertyReader();
parent::__construct([
Composer::class => static function () use ($composer): Composer {
return $composer;
},
Config::class => static function (ContainerContract $container): Config {
return $container->get(Composer::class)->getConfig();
},
IOInterface::class => static function () use ($io): IOInterface {
return $io;
},
InputInterface::class => static function (ContainerContract $container) use ($genericPropertyReader): ?InputInterface {
return $genericPropertyReader($container->get(IOInterface::class), 'input');
},
RemoteFilesystem::class => static function (ContainerContract $container): RemoteFilesystem {
return Factory::createRemoteFilesystem(
$container->get(IOInterface::class),
$container->get(Config::class)
);
},
'composer-extra' => static function (ContainerContract $container) {
return $container->get(Composer::class)->getPackage()->getExtra();
},
ParallelDownloader::class => static function (ContainerContract $container): ParallelDownloader {
$rfs = $container->get(RemoteFilesystem::class);
return new ParallelDownloader(
$container->get(IOInterface::class),
$container->get(Config::class),
$rfs->getOptions(),
$rfs->isTlsDisabled()
);
},
Downloader::class => static function (ContainerContract $container): Downloader {
$composer = $container->get(Composer::class);
$io = $container->get(IOInterface::class);
$endpoint = \getenv('AUTOMATIC_SECURITY_ENDPOINT');
if ($endpoint === false) {
$endpoint = $container->get('composer-extra')[Plugin::COMPOSER_EXTRA_KEY]['endpoint'] ?? 'https://automatic.narrowspark.com';
}
return new Downloader(
\rtrim($endpoint, '/'),
$composer,
$io,
$container->get(ParallelDownloader::class)
);
},
AuditContract::class => static function (ContainerContract $container): AuditContract {
return new Audit($container->get(Downloader::class));
},
'security_advisories' => static function (ContainerContract $container): array {
/** @var \Narrowspark\Automatic\Security\Contract\Audit $audit */
$audit = $container->get(AuditContract::class);
return $audit->getSecurityAdvisories($container->get(IOInterface::class));
},
]);
}
}