@@ -778,9 +778,9 @@ public function getClickedButton()
778778 /**
779779 * {@inheritdoc}
780780 */
781- public function getErrors ()
781+ public function getErrors ($ deep = false , $ flatten = false )
782782 {
783- return $ this ->errors ;
783+ return new FormErrorIterator ( $ this ->errors , $ this , $ deep , $ flatten ) ;
784784 }
785785
786786 /**
@@ -791,24 +791,13 @@ public function getErrors()
791791 * @param integer $level The indentation level (used internally)
792792 *
793793 * @return string A string representation of all errors
794+ *
795+ * @deprecated Deprecated since version 2.5, to be removed in 3.0. Use
796+ * {@link getErrors()} instead and cast the result to a string.
794797 */
795798 public function getErrorsAsString ($ level = 0 )
796799 {
797- $ errors = '' ;
798- foreach ($ this ->errors as $ error ) {
799- $ errors .= str_repeat (' ' , $ level ).'ERROR: ' .$ error ->getMessage ()."\n" ;
800- }
801-
802- foreach ($ this ->children as $ key => $ child ) {
803- $ errors .= str_repeat (' ' , $ level ).$ key .": \n" ;
804- if ($ child instanceof self && $ err = $ child ->getErrorsAsString ($ level + 4 )) {
805- $ errors .= $ err ;
806- } else {
807- $ errors .= str_repeat (' ' , $ level + 4 )."No errors \n" ;
808- }
809- }
810-
811- return $ errors ;
800+ return self ::indent ((string ) $ this ->getErrors (true ), $ level );
812801 }
813802
814803 /**
@@ -1115,4 +1104,19 @@ private function viewToNorm($value)
11151104
11161105 return $ value ;
11171106 }
1107+
1108+ /**
1109+ * Utility function for indenting multi-line strings.
1110+ *
1111+ * @param string $string The string
1112+ * @param integer $level The number of spaces to use for indentation
1113+ *
1114+ * @return string The indented string
1115+ */
1116+ private static function indent ($ string , $ level )
1117+ {
1118+ $ indentation = str_repeat (' ' , $ level );
1119+
1120+ return rtrim ($ indentation .str_replace ("\n" , "\n" .$ indentation , $ string ), ' ' );
1121+ }
11181122}
0 commit comments