|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dallgoot\Yaml\Nodes; |
|
4
|
|
|
|
|
5
|
|
|
use Dallgoot\Yaml\Yaml; |
|
6
|
|
|
use Dallgoot\Yaml\Regex; |
|
7
|
|
|
use Dallgoot\Yaml\Tag\TagFactory; |
|
8
|
|
|
use Dallgoot\Yaml\Nodes\Generic\NodeGeneric; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
* @author Stéphane Rebai <[email protected]> |
|
13
|
|
|
* @license Apache 2.0 |
|
14
|
|
|
* @link https://github.com/dallgoot/yaml |
|
15
|
|
|
*/ |
|
16
|
|
|
class Directive extends NodeGeneric |
|
17
|
|
|
{ |
|
18
|
|
|
private const ERROR_BUILDING = "Error : can not build Directive"; |
|
19
|
|
|
private const WARNING_LOWER_VERSION = "The declared version '%s' is obsolete, there may be features that are deprecated and therefore not handled, minimum supported is: " . Yaml::VERSION_SUPPORT; |
|
20
|
|
|
private const WARNING_HIGHER_VERSION = "The declared version '%s' is not yet supported, minimum supported is: " . Yaml::VERSION_SUPPORT; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Builds a Directive : update YamlObject if applicable. |
|
24
|
|
|
* |
|
25
|
|
|
* @param object|array $parent The parent |
|
26
|
|
|
* |
|
27
|
|
|
* @throws \ParseError If Tag handle has been already set before. |
|
28
|
|
|
*/ |
|
29
|
2 |
|
public function build(&$parent = null): void |
|
30
|
|
|
{ |
|
31
|
2 |
|
if (preg_match(Regex::DIRECTIVE_TAG, $this->raw, $matches)) { |
|
32
|
|
|
try { |
|
33
|
2 |
|
$yamlObject = $this->getRoot()->getYamlObject(); |
|
34
|
|
|
//Try registering the handle in TagFactory |
|
35
|
2 |
|
TagFactory::registerHandle($matches['handle'], $matches['uri']); |
|
36
|
1 |
|
$yamlObject->addTag($matches['handle'], $matches['uri']); |
|
37
|
1 |
|
} catch (\Throwable $e) { |
|
38
|
1 |
|
throw new \ParseError(self::ERROR_BUILDING, 1, $e); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
// TODO : is that pertinent ? : it crashes tests only for a notice |
|
42
|
|
|
// if (preg_match(Regex::DIRECTIVE_VERSION, $this->raw, $matches)) { |
|
43
|
|
|
// $contentVersion = (float) $matches['version']; |
|
44
|
|
|
// if ($contentVersion > Yaml::VERSION_SUPPORT) { |
|
45
|
|
|
// trigger_error(sprintf(self::WARNING_HIGHER_VERSION,$matches['version']), \E_USER_NOTICE ); |
|
46
|
|
|
// } |
|
47
|
|
|
// if ($contentVersion < Yaml::VERSION_SUPPORT) { |
|
48
|
|
|
// trigger_error(sprintf(self::WARNING_LOWER_VERSION, $matches['version']), \E_USER_NOTICE ); |
|
49
|
|
|
// } |
|
50
|
|
|
// } |
|
51
|
1 |
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
public function add(NodeGeneric $child): NodeGeneric |
|
55
|
|
|
{ |
|
56
|
1 |
|
return $child; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|