@@ -112,20 +112,28 @@ public function setValues($data, bool $erase = false)
112112 public function getValues ($ returnType = null , array $ controls = null )
113113 {
114114 $ form = $ this ->getForm (false );
115- if ($ form && $ form ->isSubmitted () && !$ form ->isValid ()) {
115+ if ($ form && $ form ->isSubmitted () && !$ this ->isValid ()) {
116116 trigger_error (__METHOD__ . '() invoked but the form is not valid. ' , E_USER_WARNING );
117117 }
118+ $ returnType = $ returnType === true ? self ::ARRAY : $ returnType ;
119+ return $ this ->getUnsafeValues ($ returnType , $ controls );
120+ }
118121
119- if ($ returnType === self ::ARRAY || $ returnType === true || $ this ->mappedType === self ::ARRAY ) {
120- $ returnType = self ::ARRAY ;
121- $ obj = new \stdClass ;
122122
123- } elseif (is_object ($ returnType )) {
123+ /**
124+ * Returns the potentially unvalidated values submitted by the form.
125+ * @param string|object|null $returnType 'array' for array
126+ * @param Control[]|null $controls
127+ * @return object|array
128+ */
129+ public function getUnsafeValues ($ returnType , array $ controls = null )
130+ {
131+ if (is_object ($ returnType )) {
124132 $ obj = $ returnType ;
125133
126134 } else {
127135 $ returnType = ($ returnType ?? $ this ->mappedType ?? ArrayHash::class);
128- $ obj = new $ returnType ;
136+ $ obj = $ returnType === self :: ARRAY ? new \ stdClass : new $ returnType ;
129137 }
130138
131139 $ rc = new \ReflectionClass ($ obj );
@@ -142,7 +150,7 @@ public function getValues($returnType = null, array $controls = null)
142150 $ type = $ returnType === self ::ARRAY && !$ control ->mappedType
143151 ? self ::ARRAY
144152 : ($ rc ->hasProperty ($ name ) ? Nette \Utils \Reflection::getPropertyType ($ rc ->getProperty ($ name )) : null );
145- $ obj ->$ name = $ control ->getValues ($ type , $ controls );
153+ $ obj ->$ name = $ control ->getUnsafeValues ($ type , $ controls );
146154 }
147155 }
148156
@@ -195,8 +203,8 @@ public function validate(array $controls = null): void
195203 $ params = Nette \Utils \Callback::toReflection ($ handler )->getParameters ();
196204 $ types = array_map ([Nette \Utils \Reflection::class, 'getParameterType ' ], $ params );
197205 $ args = isset ($ types [0 ]) && !$ this instanceof $ types [0 ]
198- ? [$ this ->getValues ($ types [0 ])]
199- : [$ this , isset ($ params [1 ]) ? $ this ->getValues ($ types [1 ]) : null ];
206+ ? [$ this ->getUnsafeValues ($ types [0 ], $ controls )]
207+ : [$ this , isset ($ params [1 ]) ? $ this ->getUnsafeValues ($ types [1 ], $ controls ) : null ];
200208 $ handler (...$ args );
201209 }
202210 }
0 commit comments