-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfig.php
158 lines (145 loc) · 4.82 KB
/
Config.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
namespace Drupal\Composer\Plugin\VendorHardening;
use Composer\Package\RootPackageInterface;
/**
* Determine configuration.
*
* Default configuration is merged with the root package's
* extra:drupal-core-vendor-hardening configuration.
*
* @internal
*/
class Config {
/**
* The default configuration which will always be merged with user config.
*
* @var array
*/
protected static $defaultConfig = [
'behat/mink' => ['tests'],
'behat/mink-browserkit-driver' => ['tests'],
'composer/composer' => ['bin'],
'drupal/coder' => [
'coder_sniffer/Drupal/Test',
'coder_sniffer/DrupalPractice/Test',
],
'doctrine/instantiator' => ['tests'],
'egulias/email-validator' => ['documentation', 'tests'],
'guzzlehttp/promises' => ['tests'],
'guzzlehttp/psr7' => ['tests'],
'justinrainbow/json-schema' => ['demo'],
'lullabot/mink-selenium2-driver' => ['tests'],
'lullabot/php-webdriver' => ['doc', 'test'],
'masterminds/html5' => ['bin', 'test'],
'mck89/peast' => ['doc'],
'mikey179/vfsstream' => ['src/test'],
'myclabs/deep-copy' => ['doc'],
'pear/archive_tar' => ['docs', 'tests'],
'pear/console_getopt' => ['tests'],
'pear/pear-core-minimal' => ['tests'],
'pear/pear_exception' => ['tests'],
'phar-io/manifest' => ['examples', 'tests'],
'phar-io/version' => ['tests'],
'phpdocumentor/reflection-docblock' => ['tests'],
'phpspec/prophecy' => ['fixtures', 'spec', 'tests'],
'phpunit/php-code-coverage' => ['tests'],
'phpunit/php-timer' => ['tests'],
'phpunit/phpunit' => ['tests'],
'sebastian/code-unit-reverse-lookup' => ['tests'],
'sebastian/comparator' => ['tests'],
'sebastian/diff' => ['tests'],
'sebastian/environment' => ['tests'],
'sebastian/exporter' => ['tests'],
'sebastian/global-state' => ['tests'],
'sebastian/object-enumerator' => ['tests'],
'sebastian/object-reflector' => ['tests'],
'sebastian/recursion-context' => ['tests'],
'seld/jsonlint' => ['tests'],
'squizlabs/php_codesniffer' => ['tests'],
'symfony/browser-kit' => ['Tests'],
'symfony/console' => ['Tests'],
'symfony/css-selector' => ['Tests'],
'symfony/dependency-injection' => ['Tests'],
'symfony/dom-crawler' => ['Tests'],
'symfony/filesystem' => ['Tests'],
'symfony/finder' => ['Tests'],
'symfony/event-dispatcher' => ['Tests'],
'symfony/http-foundation' => ['Tests'],
'symfony/http-kernel' => ['Tests'],
'symfony/process' => ['Tests'],
'symfony/psr-http-message-bridge' => ['Tests'],
'symfony/routing' => ['Tests'],
'symfony/serializer' => ['Tests'],
'symfony/var-dumper' => ['Tests'],
'symfony/validator' => ['Tests', 'Resources'],
'symfony/yaml' => ['Tests'],
'tbachert/spi' => ['tests'],
'theseer/tokenizer' => ['tests'],
'twig/twig' => ['doc', 'ext', 'test', 'tests'],
];
/**
* The root package.
*
* @var \Composer\Package\RootPackageInterface
*/
protected $rootPackage;
/**
* Configuration gleaned from the root package.
*
* @var array
*/
protected $configData = [];
/**
* Construct a Config object.
*
* @param \Composer\Package\RootPackageInterface $root_package
* Composer package object for the root package.
*/
public function __construct(RootPackageInterface $root_package) {
$this->rootPackage = $root_package;
}
/**
* Gets the configured list of directories to remove from the root package.
*
* This is stored in composer.json extra:drupal-core-vendor-hardening.
*
* @return array[]
* An array keyed by package name. Each array value is an array of paths,
* relative to the package.
*/
public function getAllCleanupPaths() {
if ($this->configData) {
return $this->configData;
}
// Get the root package config.
$package_config = $this->rootPackage->getExtra();
if (isset($package_config['drupal-core-vendor-hardening'])) {
$this->configData = array_change_key_case($package_config['drupal-core-vendor-hardening'], CASE_LOWER);
}
// Ensure the values are arrays.
$this->configData = array_map(function ($paths) {
return (array) $paths;
}, $this->configData);
// Merge root config with defaults.
foreach (array_change_key_case(static::$defaultConfig, CASE_LOWER) as $package => $paths) {
$this->configData[$package] = array_merge(
$this->configData[$package] ?? [],
$paths);
}
return $this->configData;
}
/**
* Get a list of paths to remove for the given package.
*
* @param string $package
* The package name.
*
* @return string[]
* Array of paths to remove, relative to the package.
*/
public function getPathsForPackage($package) {
$package = strtolower($package);
$paths = $this->getAllCleanupPaths();
return $paths[$package] ?? [];
}
}