-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathConfiguration.php
157 lines (140 loc) · 4.47 KB
/
Configuration.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
<?php
declare(strict_types=1);
/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
* Pádraic Brady <padraic.brady@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Humbug\PhpScoper\Configuration;
use Humbug\PhpScoper\Configuration\Throwable\InvalidConfigurationValue;
use Humbug\PhpScoper\Patcher\Patcher;
use PhpParser\PhpVersion;
final class Configuration
{
private readonly Prefix $prefix;
/**
* @param non-empty-string|null $path Absolute canonical path to the configuration file loaded.
* @param non-empty-string|null $outputDir Absolute canonical path to the output directory.
* @param non-empty-string $prefix The prefix applied.
* @param array<string, array{string, string}> $filesWithContents Array of tuple with the
* first argument being the file path and the second
* its contents
* @param array<string, array{string, string}> $excludedFilesWithContents Array of tuple
* with the first argument being the file path and
* the second its contents
*
* @throws InvalidConfigurationValue
*/
public function __construct(
private ?string $path,
private ?string $outputDir,
string|Prefix $prefix,
private ?PhpVersion $phpVersion,
private array $filesWithContents,
private array $excludedFilesWithContents,
private Patcher $patcher,
private SymbolsConfiguration $symbolsConfiguration
) {
$this->prefix = $prefix instanceof Prefix
? $prefix
: new Prefix($prefix);
}
/**
* @return non-empty-string|null Absolute canonical path
*/
public function getPath(): ?string
{
return $this->path;
}
/**
* @return non-empty-string|null Absolute canonical path
*/
public function getOutputDir(): ?string
{
return $this->outputDir;
}
/**
* @param non-empty-string $prefix
*
* @throws InvalidConfigurationValue
*/
public function withPrefix(string $prefix): self
{
return new self(
$this->path,
$this->outputDir,
$prefix,
$this->phpVersion,
$this->filesWithContents,
$this->excludedFilesWithContents,
$this->patcher,
$this->symbolsConfiguration,
);
}
/**
* @return non-empty-string
*/
public function getPrefix(): string
{
return $this->prefix->toString();
}
/**
* @param array<string, array{string, string}> $filesWithContents
*/
public function withFilesWithContents(array $filesWithContents): self
{
return new self(
$this->path,
$this->outputDir,
$this->prefix,
$this->phpVersion,
$filesWithContents,
$this->excludedFilesWithContents,
$this->patcher,
$this->symbolsConfiguration,
);
}
/**
* @return array<string, array{string, string}>
*/
public function getFilesWithContents(): array
{
return $this->filesWithContents;
}
/**
* @return array<string, array{string, string}>
*/
public function getExcludedFilesWithContents(): array
{
return $this->excludedFilesWithContents;
}
public function withPatcher(Patcher $patcher): self
{
return new self(
$this->path,
$this->outputDir,
$this->prefix,
$this->phpVersion,
$this->filesWithContents,
$this->excludedFilesWithContents,
$patcher,
$this->symbolsConfiguration,
);
}
public function getPatcher(): Patcher
{
return $this->patcher;
}
public function getSymbolsConfiguration(): SymbolsConfiguration
{
return $this->symbolsConfiguration;
}
public function getPhpVersion(): ?PhpVersion
{
return $this->phpVersion;
}
}