-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPhpFileLoader.php
More file actions
52 lines (44 loc) · 1.53 KB
/
PhpFileLoader.php
File metadata and controls
52 lines (44 loc) · 1.53 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
<?php
declare(strict_types=1);
namespace MakinaCorpus\DbToolsBundle\Anonymization\Config\Loader;
use MakinaCorpus\DbToolsBundle\Error\ConfigurationException;
class PhpFileLoader extends ArrayLoader
{
public function __construct(
private string $file,
string $connectionName = 'default',
/**
* Root directory from which the configuration was loaded. It allows
* later file loading (for example, when sources are CSV or TXT files).
*
* If not set, the file directory will be used instead. If set, it will
* override the file directory.
*/
?string $basePath = null,
) {
// @todo dirname() is purely soft logic, it does not imply any
// syscalls, whereas realpah() may.
$basePath ??= \realpath(\dirname($file));
parent::__construct([], $connectionName, $basePath);
}
#[\Override]
protected function getData(): array
{
try {
$data = require $this->file;
} catch (\Throwable $e) {
throw new ConfigurationException(\sprintf(
"An error occurred when loading \"%s\" configuration file: %s",
$this->file,
$e->getMessage()
), 0, $e);
}
if (!\is_array($data)) {
throw new ConfigurationException(\sprintf(
"File \"%s\" is not a valid PHP anonymization configuration file (must return an array).",
$this->file
));
}
return $data;
}
}