1- <?php
2- namespace Krishna \DataValidator ;
3-
4- class ErrorReader {
5- public array $ errors = [];
6- private ?string $ _errorstring = null ;
7- public function __construct (array $ errors ) {
8- $ this ->_traverse ($ errors );
9- }
10- private function _traverse (array $ a , string $ pre = '' ) {
11- foreach ($ a as $ k =>$ v ) {
12- if (is_array ($ v )) {
13- $ this ->_traverse ($ v , "{$ pre }[ $ { k}] " );
14- } else {
15- $ this ->errors [] = "{$ pre }[ {$ k }]: {$ v }" ;
16- }
17- }
18- }
19- public function __toString () : string {
20- $ this ->_errorstring ??= json_encode ($ this ->errors , JSON_PRETTY_PRINT | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR );
21- return $ this ->_errorstring ;
22- }
23- public function __debugInfo () {
24- return $ this ->errors ;
25- }
26- public function getFormattedErrors (string $ seperator = ', ' ) : string {
27- return implode ($ seperator , $ this ->errors );
28- }
1+ <?php
2+ namespace Krishna \DataValidator ;
3+
4+ class ErrorReader {
5+ public array $ errors = [];
6+ private ?string $ _errorstring = null ;
7+ public function __construct (array $ errors ) {
8+ $ this ->_traverse ($ errors );
9+ }
10+ private function _traverse (array $ a , string $ pre = '' ) {
11+ foreach ($ a as $ k =>$ v ) {
12+ if (is_array ($ v )) {
13+ $ this ->_traverse ($ v , "{$ pre }[ { $ k }] " );
14+ } else {
15+ $ this ->errors [] = "{$ pre }[ {$ k }]: {$ v }" ;
16+ }
17+ }
18+ }
19+ public function __toString () : string {
20+ $ this ->_errorstring ??= json_encode ($ this ->errors , JSON_PRETTY_PRINT | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR );
21+ return $ this ->_errorstring ;
22+ }
23+ public function __debugInfo () {
24+ return $ this ->errors ;
25+ }
26+ public function getFormattedErrors (string $ seperator = ', ' ) : string {
27+ return implode ($ seperator , $ this ->errors );
28+ }
2929}
0 commit comments