|
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\Builder; |
|
11
|
|
|
|
|
12
|
|
|
use Railt\Parser\Ast\RuleInterface; |
|
13
|
|
|
use Railt\Reflection\Contracts\Definition; |
|
14
|
|
|
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesTypeIndication; |
|
15
|
|
|
use Railt\Reflection\Contracts\Definition\TypeDefinition; |
|
16
|
|
|
use Railt\SDL\Compiler\Ast\Value\ValueInterface; |
|
17
|
|
|
use Railt\SDL\Compiler\Builder\Common\ValueBuilder; |
|
18
|
|
|
use Railt\SDL\Compiler\Factory; |
|
19
|
|
|
use Railt\SDL\Compiler\Pipeline; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Builder |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class Builder implements BuilderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Pipeline |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $when; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var Factory |
|
33
|
|
|
*/ |
|
34
|
|
|
private $factory; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Builder constructor. |
|
38
|
|
|
* @param Pipeline $pipeline |
|
39
|
|
|
* @param Factory $factory |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function __construct(Pipeline $pipeline, Factory $factory) |
|
42
|
|
|
{ |
|
43
|
1 |
|
$this->when = $pipeline; |
|
44
|
1 |
|
$this->factory = $factory; |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param Definition|ProvidesTypeIndication $from |
|
49
|
|
|
* @param ValueInterface $value |
|
50
|
|
|
* @return array|mixed |
|
51
|
|
|
* @throws \Railt\Io\Exception\ExternalFileException |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function valueOf(ProvidesTypeIndication $from, ValueInterface $value) |
|
54
|
|
|
{ |
|
55
|
|
|
return (new ValueBuilder($from))->valueOf($value); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string $type |
|
60
|
|
|
* @param TypeDefinition $from |
|
61
|
|
|
* @return TypeDefinition |
|
62
|
|
|
* @throws \Railt\Reflection\Exception\TypeNotFoundException |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function load(string $type, TypeDefinition $from): TypeDefinition |
|
65
|
|
|
{ |
|
66
|
|
|
$dict = $from->getDictionary(); |
|
67
|
|
|
|
|
68
|
|
|
return $dict->get($type, $from); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param RuleInterface $ast |
|
73
|
|
|
* @param Definition $parent |
|
74
|
|
|
* @return Definition |
|
75
|
|
|
* @throws \Railt\Io\Exception\ExternalFileException |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function dependent(RuleInterface $ast, Definition $parent): Definition |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->factory->build($ast, $parent); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|