-
Notifications
You must be signed in to change notification settings - Fork 1
/
Context.php
97 lines (89 loc) · 2.33 KB
/
Context.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
<?php
/**
* @package \axy\ml
* @author Oleg Grigoriev <[email protected]>
*/
namespace axy\ml;
use axy\ml\helpers\Block;
use axy\magic\LazyField;
use axy\magic\ReadOnly;
/**
* The context of the parsing
*
* @property-read \axy\ml\Result $result
* the result of the parsing of the current document
* @property-read \axy\ml\Options $options
* the parsing options
* @property-read \axy\ml\TagsList $tags
* the list of available tags
* @property-read mixed $custom
* the custom context
* @property-read Block $block
* a current block (during render)
* @property-read array $errors
* the errors list of the last parsing
* @property-read object $vars
* custom variables of the parsing
*/
class Context
{
use LazyField;
use ReadOnly;
/**
* The constructor
*
* @param \axy\ml\Result $result
* @param \axy\ml\Options $options
* @param \axy\ml\TagsList $tags
* @param mixed $custom
*/
public function __construct(Result $result, Options $options, TagsList $tags, $custom)
{
$this->magicFields['fields'] = [
'result' => $result,
'options' => $options,
'tags' => $tags,
'custom' => $custom,
'errors' => [],
'block' => null,
'vars' => null,
];
}
/**
* Initialization before rendering
*
* @param array $errors [optional]
* the errors list of the tokenize
*/
public function startRender(array $errors = [])
{
$this->magicFields['fields']['vars'] = (object)[];
$this->magicFields['fields']['errors'] = $errors;
}
/**
* Ends the parsing
*/
public function endRender()
{
$this->magicFields['fields']['vars'] = (object)[];
$this->magicFields['fields']['errors'] = [];
}
/**
* Sets the current block (while render)
*
* @param Block $block
*/
public function setCurrentBlock(Block $block = null)
{
$this->magicFields['fields']['block'] = $block;
}
/**
* Appends an error to the errors list
*
* @param \axy\ml\Error $error
*/
public function addError($error)
{
$this->magicFields['fields']['errors'][] = $error;
}
}