-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathElement.php
More file actions
128 lines (95 loc) · 2.52 KB
/
Copy pathElement.php
File metadata and controls
128 lines (95 loc) · 2.52 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
declare(strict_types=1);
namespace PHPCensor\Form;
use PHPCensor\View;
/**
* @package PHP Censor
* @subpackage Application
*
* @author Dan Cryer <dan@block8.co.uk>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
abstract class Element
{
protected string $name = '';
protected string $id = '';
protected string $label = '';
protected string $class = '';
protected string $containerClass = '';
protected ?Element $parent = null;
public function __construct(?string $name = null)
{
if (!\is_null($name)) {
$this->setName($name);
}
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = \strtolower(\preg_replace('/([^a-zA-Z0-9_\-%])/', '', $name));
return $this;
}
public function getId(): string
{
return !$this->id
? ('element-' . $this->name)
: $this->id;
}
public function setId(string $id): self
{
$this->id = $id;
return $this;
}
public function getLabel(): string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getClass(): string
{
return $this->class;
}
public function setClass(string $class): self
{
$this->class = $class;
return $this;
}
public function getContainerClass(): string
{
return $this->containerClass;
}
public function setContainerClass(string $class): self
{
$this->containerClass = $class;
return $this;
}
public function setParent(Element $parent): self
{
$this->parent = $parent;
return $this;
}
public function render(?string $viewFile = null): string
{
if (\is_null($viewFile)) {
$class = \explode('\\', \get_called_class());
$viewFile = \end($class);
}
$view = new View('Form/' . $viewFile);
$view->name = $this->getName();
$view->id = $this->getId();
$view->label = $this->getLabel();
$view->class = $this->getClass();
$view->containerClass = $this->getContainerClass();
$view->parent = $this->parent;
$this->onPreRender($view);
return $view->render();
}
abstract protected function onPreRender(View &$view): void;
}