1717 */
1818class Template extends LatteTemplate
1919{
20- /** @var array */
21- private $ params = [];
22-
23-
2420 /**
2521 * Adds new template parameter.
2622 * @return static
2723 */
2824 public function add (string $ name , $ value )
2925 {
30- if (array_key_exists ( $ name , $ this -> params )) {
26+ if (property_exists ( $ this , $ name )) {
3127 throw new Nette \InvalidStateException ("The variable ' $ name' already exists. " );
3228 }
33- $ this ->params [ $ name] = $ value ;
29+ $ this ->$ name = $ value ;
3430 return $ this ;
3531 }
3632
@@ -41,7 +37,9 @@ public function add(string $name, $value)
4137 */
4238 public function setParameters (array $ params )
4339 {
44- $ this ->params = $ params + $ this ->params ;
40+ foreach ($ params as $ k => $ v ) {
41+ $ this ->$ k = $ v ;
42+ }
4543 return $ this ;
4644 }
4745
@@ -51,47 +49,6 @@ public function setParameters(array $params)
5149 */
5250 public function getParameters (): array
5351 {
54- return $ this ->params ;
55- }
56-
57-
58- /**
59- * Sets a template parameter. Do not call directly.
60- */
61- public function __set (string $ name , $ value ): void
62- {
63- $ this ->params [$ name ] = $ value ;
64- }
65-
66-
67- /**
68- * Returns a template parameter. Do not call directly.
69- * @return mixed value
70- */
71- public function &__get (string $ name )
72- {
73- if (!array_key_exists ($ name , $ this ->params )) {
74- trigger_error ("The variable ' $ name' does not exist in template. " , E_USER_NOTICE );
75- }
76-
77- return $ this ->params [$ name ];
78- }
79-
80-
81- /**
82- * Determines whether parameter is defined. Do not call directly.
83- */
84- public function __isset (string $ name ): bool
85- {
86- return isset ($ this ->params [$ name ]);
87- }
88-
89-
90- /**
91- * Removes a template parameter. Do not call directly.
92- */
93- public function __unset (string $ name ): void
94- {
95- unset($ this ->params [$ name ]);
52+ return get_object_vars ($ this );
9653 }
9754}
0 commit comments