1 | <?php |
||
11 | class Form |
||
12 | { |
||
13 | /** |
||
14 | * The form fields. |
||
15 | * |
||
16 | * @var Collection |
||
17 | */ |
||
18 | protected $fields; |
||
19 | |||
20 | /** |
||
21 | * The form model. |
||
22 | * |
||
23 | * @var Model |
||
24 | */ |
||
25 | protected $model; |
||
26 | |||
27 | /** |
||
28 | * The form theme. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $theme; |
||
33 | |||
34 | /** |
||
35 | * The helper of former. |
||
36 | * |
||
37 | * @var FormerHelper |
||
38 | */ |
||
39 | protected $helper; |
||
40 | |||
41 | /** |
||
42 | * Form constructor. |
||
43 | * |
||
44 | * @param Model|null $model |
||
45 | * @param FormerHelper $formerHelper |
||
46 | */ |
||
47 | public function __construct(Model $model = null, FormerHelper $formerHelper) |
||
54 | |||
55 | /** |
||
56 | * Get the model fields. |
||
57 | * |
||
58 | * @return Collection |
||
59 | */ |
||
60 | public function getFields(): Collection |
||
64 | |||
65 | /** |
||
66 | * Set the model fields. |
||
67 | * |
||
68 | * @param string $input |
||
69 | * @param string $name |
||
70 | * @param array $rules |
||
71 | */ |
||
72 | public function addField($input, $name, array $rules) |
||
82 | |||
83 | /** |
||
84 | * Get the form model. |
||
85 | * |
||
86 | * @return Model |
||
87 | */ |
||
88 | public function getModel(): Model |
||
92 | |||
93 | public function getHelper(): FormerHelper |
||
97 | |||
98 | /** |
||
99 | * Set the form model. |
||
100 | * |
||
101 | * @param Model $model |
||
102 | */ |
||
103 | public function setModel(Model $model) |
||
107 | |||
108 | /** |
||
109 | * Set the form theme. |
||
110 | * |
||
111 | * @param string|null $theme |
||
112 | */ |
||
113 | public function setTheme($theme) |
||
117 | |||
118 | public function start() |
||
126 | |||
127 | public function end() |
||
135 | |||
136 | public function field(string $name) |
||
147 | } |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: