1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\SDL\Compiler\Processor; |
11
|
|
|
|
12
|
|
|
use Railt\Parser\Ast\RuleInterface; |
13
|
|
|
use Railt\Reflection\Contracts\Definition; |
14
|
|
|
use Railt\Reflection\Contracts\Document; |
15
|
|
|
use Railt\SDL\Compiler\Factory; |
16
|
|
|
use Railt\SDL\Compiler\Pipeline; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class DefinitionProcessor |
20
|
|
|
*/ |
21
|
|
|
abstract class DefinitionProcessor implements ProcessorInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Document|\Railt\Reflection\Document |
25
|
|
|
*/ |
26
|
|
|
protected $document; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Pipeline |
30
|
|
|
*/ |
31
|
|
|
protected $pipeline; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Factory |
35
|
|
|
*/ |
36
|
|
|
private $factory; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* DefinitionProcessor constructor. |
40
|
|
|
* @param Document $document |
41
|
|
|
* @param Pipeline $pipeline |
42
|
|
|
* @param Factory $factory |
43
|
|
|
*/ |
44
|
1 |
|
public function __construct(Document $document, Pipeline $pipeline, Factory $factory) |
45
|
|
|
{ |
46
|
1 |
|
$this->document = $document; |
47
|
1 |
|
$this->pipeline = $pipeline; |
48
|
1 |
|
$this->factory = $factory; |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param RuleInterface $rule |
53
|
|
|
* @return Definition |
54
|
|
|
* @throws \Railt\Io\Exception\ExternalFileException |
55
|
|
|
*/ |
56
|
|
|
protected function build(RuleInterface $rule): Definition |
57
|
|
|
{ |
58
|
|
|
return $this->factory->build($rule); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param \Closure $then |
63
|
|
|
* @return DefinitionProcessor |
64
|
|
|
*/ |
65
|
|
|
protected function deferred(\Closure $then): DefinitionProcessor |
66
|
|
|
{ |
67
|
|
|
$this->pipeline->push(1, $then); |
68
|
|
|
|
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param \Closure $then |
74
|
|
|
* @return DefinitionProcessor |
75
|
|
|
*/ |
76
|
|
|
protected function then(\Closure $then): DefinitionProcessor |
77
|
|
|
{ |
78
|
|
|
$this->pipeline->push(2, $then); |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|