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