public function withErrors(array $errors = []): CollectionElement
    {
        $this->allErrors = $errors;

        array_walk(
            $this->elements,
            function (ElementInterface $element) use ($errors) {
                $name = $element->name();
                if (isset($errors[$name]) && $element instanceof ErrorAwareInterface) {
                    $element->withErrors($errors);
                    unset($errors[$name]);
                }
            }
        );

        // assign errors without matches to the collection itself.
        $this->errors = $errors;

        return $this;
    }
public function withErrors(array $errors = []): CollectionElement
    {
        $this->allErrors = $errors;

        array_walk(
            $this->elements,
            function (ElementInterface $element) use ($errors) {
                $name = $element->name();
                if (isset($errors[$name]) && $element instanceof ErrorAwareInterface) {
                    $element->withErrors($errors);
                    unset($errors[$name]);
                }
            }
        );

        // assign errors without matches to the collection itself.
        $this->errors = $errors;

        return $this;
    }
public function withErrors ( array $ errors = [ ] ) : CollectionElement { $ this -> allErrors = $ errors ; array_walk ( $ this -> elements , function ( ElementInterface $ element ) use ( $ errors ) { $ name = $ element -> name ( ) ; if ( isset ( $ errors [ $ name ] ) && $ element instanceof ErrorAwareInterface ) { $ element -> withErrors ( $ errors ) ; unset ( $ errors [ $ name ] ) ; } } ) ; // assign errors without matches to the collection itself. $ this -> errors = $ errors ; return $ this ; }
Delegate errors down to the children.

@param array $errors

@return CollectionElement
Delegate errors down to the children .