1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Formularium; |
4
|
|
|
|
5
|
|
|
use Formularium\Exception\ClassNotFoundException; |
6
|
|
|
use Formularium\Exception\Exception; |
7
|
|
|
use Formularium\HTMLElement; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Abstract base class for frameworks. Each framework should have a class inheriting |
11
|
|
|
* from this class. |
12
|
|
|
*/ |
13
|
|
|
abstract class Framework |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name; |
19
|
|
|
|
20
|
6 |
|
/** |
21
|
|
|
* Options for rendering |
22
|
6 |
|
* @var array |
23
|
6 |
|
*/ |
24
|
|
|
protected $options = []; |
25
|
8 |
|
|
26
|
|
|
public function __construct(string $name) |
27
|
8 |
|
{ |
28
|
8 |
|
$this->name = $name; |
29
|
2 |
|
} |
30
|
|
|
|
31
|
6 |
|
public static function factory(string $framework = ''): Framework |
32
|
|
|
{ |
33
|
|
|
$class = "\\Formularium\\Frontend\\$framework\\Framework"; |
34
|
|
|
if (!class_exists($class)) { |
35
|
|
|
throw new ClassNotFoundException("Invalid framework $framework"); |
36
|
|
|
} |
37
|
|
|
return new $class(); |
38
|
|
|
} |
39
|
2 |
|
|
40
|
|
|
public function getRenderable(Datatype $datatype): Renderable |
41
|
2 |
|
{ |
42
|
|
|
return Renderable::factory($datatype, $this); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getName(): string |
46
|
|
|
{ |
47
|
|
|
return $this->name; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $name |
52
|
|
|
* @param mixed $value |
53
|
|
|
* @return mixed |
54
|
|
|
*/ |
55
|
|
|
public function getOption(string $name, $value = null) |
56
|
|
|
{ |
57
|
|
|
return $this->options[$name] ?? $value; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
* @param string $name |
63
|
|
|
* @param mixed $value |
64
|
|
|
* @return self |
65
|
|
|
*/ |
66
|
|
|
public function setOption(string $name, $value): self |
67
|
|
|
{ |
68
|
|
|
$this->options[$name] = $value; |
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set a new option |
74
|
|
|
* |
75
|
|
|
* @param array $options |
76
|
|
|
* @return self |
77
|
|
|
*/ |
78
|
|
|
public function setOptions(array $options): self |
79
|
|
|
{ |
80
|
|
|
$this->options = $options; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns a string with the <head> HTML to generate standalone files. |
86
|
|
|
* This is used by the kitchensink generator. |
87
|
|
|
* |
88
|
|
|
* @param HTMLElement $head |
89
|
|
|
* @return void |
90
|
|
|
* @codeCoverageIgnore |
91
|
|
|
*/ |
92
|
|
|
public function htmlHead(HTMLElement &$head) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns a string with things to add to the footer of the page (such as scripts) |
98
|
|
|
* This is used by the kitchensink generator. |
99
|
|
|
* |
100
|
|
|
* @param HTMLElement $head |
101
|
|
|
* @return void |
102
|
|
|
* @codeCoverageIgnore |
103
|
|
|
*/ |
104
|
|
|
public function htmlFooter(HTMLElement &$head) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param Model $m |
110
|
|
|
* @param HTMLElement[] $elements |
111
|
|
|
* @param string $previousCompose |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function editableCompose(Model $m, array $elements, string $previousCompose): string |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
return $previousCompose; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param Model $m |
121
|
|
|
* @param HTMLElement[] $elements |
122
|
|
|
* @param string $previousCompose |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function viewableCompose(Model $m, array $elements, string $previousCompose): string |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
return $previousCompose; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.