1 | <?php |
||
14 | class TrustStoreLoader |
||
15 | { |
||
16 | /** |
||
17 | * Loads the currently installed ca-certificates file. |
||
18 | * The approach taken by composer/ca-bundle is to attempt |
||
19 | * to load certificates if openssl-like envvars and |
||
20 | * config values are set. |
||
21 | * |
||
22 | * If $allowFallback is false, and the bundled composer |
||
23 | * ca file is returned, an exception will be thrown. |
||
24 | * |
||
25 | * @see CaBundle::getSystemCaRootBundlePath() |
||
26 | * @param bool $allowFallback |
||
27 | * @return CertificateBundle |
||
28 | */ |
||
29 | 9 | public static function fromSystem(bool $allowFallback = true): CertificateBundle |
|
30 | { |
||
31 | 9 | $rootBundlePath = CaBundle::getSystemCaRootBundlePath(); |
|
32 | |||
33 | 9 | if (!$allowFallback && CaBundle::getBundledCaBundlePath() === $rootBundlePath) { |
|
34 | 1 | throw new \RuntimeException("Fallback to composer ca-bundle is disabled - you should install the ca-certificates package"); |
|
35 | } |
||
36 | |||
37 | 8 | if (is_dir($rootBundlePath)) { |
|
38 | 1 | return self::fromDirectory($rootBundlePath); |
|
39 | } else { |
||
40 | 7 | return self::fromFile($rootBundlePath); |
|
41 | } |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Loads a trust store completely controlled by what is |
||
46 | * included in the `composer/ca-bundle` package. |
||
47 | * @return CertificateBundle |
||
48 | */ |
||
49 | 1 | public static function fromComposerBundle(): CertificateBundle |
|
50 | { |
||
51 | 1 | return self::fromFile(CaBundle::getBundledCaBundlePath()); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Load a trust store from a pem bundle file (can contain |
||
56 | * multiple certificates) |
||
57 | * |
||
58 | * @param string $file |
||
59 | * @return CertificateBundle |
||
60 | * @throws Bip70Exception |
||
61 | */ |
||
62 | 10 | public static function fromFile(string $file): CertificateBundle |
|
80 | |||
81 | /** |
||
82 | * Load a trust store from a pem bundle file (can contain |
||
83 | * multiple certificates) |
||
84 | * |
||
85 | * @param string $dir |
||
86 | * @return CertificateBundle |
||
87 | * @throws Bip70Exception |
||
88 | */ |
||
89 | 4 | public static function fromDirectory(string $dir): CertificateBundle |
|
111 | } |
||
112 |