-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.php
More file actions
141 lines (123 loc) · 4.08 KB
/
generate.php
File metadata and controls
141 lines (123 loc) · 4.08 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
use Laminas\Code\Generator\ClassGenerator;
use Laminas\Code\Generator\FileGenerator;
use Laminas\Code\Reflection\ClassReflection;
use OpenRegion\PhpcadesMeta\AboutModifier;
use OpenRegion\PhpcadesMeta\ClassModifierInterface;
use OpenRegion\PhpcadesMeta\CPAlgorithmModifier;
use OpenRegion\PhpcadesMeta\CPAlgorithmPhpStormMeta;
use OpenRegion\PhpcadesMeta\CPAttributeModifier;
use OpenRegion\PhpcadesMeta\CPAttributePhpStormMeta;
use OpenRegion\PhpcadesMeta\CPAttributesModifier;
use OpenRegion\PhpcadesMeta\CPBasicConstraintsModifier;
use OpenRegion\PhpcadesMeta\CPBasicConstraintsPhpStormMeta;
use OpenRegion\PhpcadesMeta\CPCertificateModifier;
use OpenRegion\PhpcadesMeta\CPCertificatePhpStormMeta;
use OpenRegion\PhpcadesMeta\CPCertificatesModifier;
use OpenRegion\PhpcadesMeta\CPCertificatesPhpStormMeta;
use OpenRegion\PhpcadesMeta\CPHashedDataModifier;
use OpenRegion\PhpcadesMeta\CPHashedDataPhpStormMeta;
use OpenRegion\PhpcadesMeta\CPOIDModifier;
use OpenRegion\PhpcadesMeta\CPPrivateKeyModifier;
use OpenRegion\PhpcadesMeta\CPPrivateKeyPhpStormMeta;
use OpenRegion\PhpcadesMeta\CPPublicKeyModifier;
use OpenRegion\PhpcadesMeta\CPRawSignatureModifier;
use OpenRegion\PhpcadesMeta\CPSignedDataModifier;
use OpenRegion\PhpcadesMeta\CPSignedDataPhpStormMeta;
use OpenRegion\PhpcadesMeta\CPSignerModifier;
use OpenRegion\PhpcadesMeta\CPSignerPhpStormMeta;
use OpenRegion\PhpcadesMeta\CPStoreModifier;
use OpenRegion\PhpcadesMeta\CPStorePhpStormMeta;
use OpenRegion\PhpcadesMeta\PhpStormMetaInterface;
use OpenRegion\PhpcadesMeta\VersionModifier;
require_once __DIR__ . '/vendor/autoload.php';
/**
* Cleanup
*/
$removeFiles = static function (string $file) {
if (is_file($file)) {
unlink($file);
}
};
array_map(
$removeFiles,
glob(__DIR__ . '/dist/meta/.*.php') ?: [],
);
array_map(
$removeFiles,
glob(__DIR__ . '/dist/*.php') ?: [],
);
/**
* Main meta
*/
/** @var array<ClassModifierInterface|null> $classes */
$classes = [
'About' => AboutModifier::class,
'CPAlgorithm' => CPAlgorithmModifier::class,
'CPAttribute' => CPAttributeModifier::class,
'CPAttributes' => CPAttributesModifier::class,
'CPBasicConstraints' => CPBasicConstraintsModifier::class,
'CPCardholderData' => null,
'CPCertificate' => CPCertificateModifier::class,
'CPCertificates' => CPCertificatesModifier::class,
'CPCertificateStatus' => null,
'CPEKU' => null,
'CPEKUs' => null,
'CPEncodedData' => null,
'CPEnvelopedData' => null,
'CPExtendedKeyUsage' => null,
'CPHashedData' => CPHashedDataModifier::class,
'CPKeyUsage' => null,
'CPOID' => CPOIDModifier::class,
'CPPrivateKey' => CPPrivateKeyModifier::class,
'CPPublicKey' => CPPublicKeyModifier::class,
'CPRawSignature' => CPRawSignatureModifier::class,
'CPRecipients' => null,
'CPSignedData' => CPSignedDataModifier::class,
'CPSignedXML' => null,
'CPSigner' => CPSignerModifier::class,
'CPSigners' => null,
'CPStore' => CPStoreModifier::class,
'SymmetricAlgorithm' => null,
'Version' => VersionModifier::class,
];
foreach ($classes as $className => $classModifier) {
if (!class_exists($className, false)) {
continue;
}
$classGenerator = ClassGenerator::fromReflection(
new ClassReflection($className)
);
if ($classModifier !== null) {
$classModifier::apply($classGenerator);
}
$fileGenerator = (new FileGenerator)->setClass($classGenerator);
file_put_contents(__DIR__ . "/dist/{$className}.php", $fileGenerator->generate());
}
/**
* PhpStorm metadata
*/
/** @var PhpStormMetaInterface[] $phpStormMetas */
$phpStormMetas = [
CPAlgorithmPhpStormMeta::class,
CPAttributePhpStormMeta::class,
CPBasicConstraintsPhpStormMeta::class,
CPCertificatePhpStormMeta::class,
CPCertificatesPhpStormMeta::class,
CPHashedDataPhpStormMeta::class,
CPPrivateKeyPhpStormMeta::class,
CPSignedDataPhpStormMeta::class,
CPSignerPhpStormMeta::class,
CPStorePhpStormMeta::class,
];
$body = <<<'PHP'
<?php
namespace PHPSTORM_META {
PHP;
foreach ($phpStormMetas as $phpStormMeta) {
$body .= "\n" . $phpStormMeta::getMeta() . "\n";
}
$body .= <<<'PHP'
}
PHP;
file_put_contents(__DIR__ . '/dist/meta/.phpstorm.meta.php', $body);