public function messages(string $slug = '', bool $by_slug = false): array
    {
        if (!$slug) { // All messages (i.e., for all slugs)?
            //
            if ($by_slug) { // All messages keyed by slug?
                return $this->errors ?: [$this->default_slug => $this->default_message];
                //
            } else { // Merge all messages into a single array.
                $messages = []; // Initialize array.

                foreach ($this->errors as $_slug => $_messages) {
                    $messages = array_merge($messages, $_messages);
                } // unset($_slug, $_messages); // Housekeeping.

                return $messages ?: [$this->default_message];
            }
        } else { // For a specific slug.
            $messages = $this->errors[$slug] ?? [];
            return $messages ?: [$this->default_message];
        }
    }
public function messages(string $slug = '', bool $by_slug = false): array
    {
        if (!$slug) { // All messages (i.e., for all slugs)?
            //
            if ($by_slug) { // All messages keyed by slug?
                return $this->errors ?: [$this->default_slug => $this->default_message];
                //
            } else { // Merge all messages into a single array.
                $messages = []; // Initialize array.

                foreach ($this->errors as $_slug => $_messages) {
                    $messages = array_merge($messages, $_messages);
                } // unset($_slug, $_messages); // Housekeeping.

                return $messages ?: [$this->default_message];
            }
        } else { // For a specific slug.
            $messages = $this->errors[$slug] ?? [];
            return $messages ?: [$this->default_message];
        }
    }
public function messages ( string $ slug = '' , bool $ by_slug = false ) : array { if ( ! $ slug ) { // All messages (i.e., for all slugs)? // if ( $ by_slug ) { // All messages keyed by slug? return $ this -> errors ? : [ $ this -> default_slug => $ this -> default_message ] ; // } else { // Merge all messages into a single array. $ messages = [ ] ; // Initialize array. foreach ( $ this -> errors as $ _slug => $ _messages ) { $ messages = array_merge ( $ messages , $ _messages ) ; } // unset($_slug, $_messages); // Housekeeping. return $ messages ? : [ $ this -> default_message ] ; } } else { // For a specific slug. $ messages = $ this -> errors [ $ slug ] ?? [ ] ; return $ messages ? : [ $ this -> default_message ] ; } }
Get error messages.

@since 160710 Error utils.

@param string $slug    Error slug.
@param bool   $by_slug All errors by slug?

@return string[] An array of error messages.
Get error messages .