-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYmlFile.php
More file actions
93 lines (82 loc) · 2.26 KB
/
YmlFile.php
File metadata and controls
93 lines (82 loc) · 2.26 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
<?php
/**
*
* EPV :: The phpBB Forum Extension Pre Validator.
*
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace Phpbb\Epv\Files\Type;
use Phpbb\Epv\Files\BaseFile;
use Phpbb\Epv\Files\Exception\FileLoadException;
use Phpbb\Epv\Tests\Type;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
class YmlFile extends BaseFile implements YmlFileInterface
{
/** @var array */
protected $yamlFile;
public function __construct($debug, $filename, $rundir)
{
parent::__construct($debug, $filename, $rundir);
try
{
$content = Yaml::parse($this->fileData);
if (!is_array($content))
{
throw new ParseException("Empty file");
}
// Look for imports
if (isset($content['imports']) && is_array($content['imports']))
{
// Imports are defined relatively, get the directory based on the current file
$currentPathInfo = pathinfo($filename);
$dirname = $currentPathInfo['dirname'];
foreach ($content['imports'] as $import)
{
if (isset($import['resource']))
{
try
{
$importYmlFileName = $dirname . '/' . $import['resource'];
$importYmlFile = new YmlFile($debug, $importYmlFileName, $rundir);
$extraContent = $importYmlFile->getYaml();
}
catch (FileLoadException $ex)
{
// The imported yml file will be loaded individually later.
// Let's avoid duplicate error messages here and continue with the current yml.
$extraContent = array();
}
// Imports are at the top of the yaml file, so these should be loaded first.
// The values of the current yaml file will overwrite existing array values of the imports.
$content = array_replace_recursive($extraContent, $content);
}
}
}
$this->yamlFile = $content;
}
catch (ParseException $ex)
{
throw new FileLoadException("Parsing yaml file ($filename) failed: " . $ex->getMessage());
}
}
/**
* Get an array with the data in the yaml file.
*
* @return array
*/
public function getYaml(): array
{
return $this->yamlFile;
}
/**
* Get the file type for the specific file.
* @return int
*/
function getFileType(): int
{
return Type::TYPE_YML;
}
}