Respect\Validation\Exceptions\NestedValidationException::getFullMessage PHP Method

getFullMessage() public method

public getFullMessage ( ) : string
return string
    public function getFullMessage()
    {
        $marker = '-';
        $messages = [];
        $exceptions = $this->getIterator();
        if ($this->hasCustomTemplate() || count($exceptions) != 1) {
            $messages[] = sprintf('%s %s', $marker, $this->getMessage());
        }
        foreach ($exceptions as $exception) {
            $depth = $exceptions[$exception]['depth'];
            $prefix = str_repeat(' ', $depth * 2);
            $messages[] = sprintf('%s%s %s', $prefix, $marker, $exception->getMessage());
        }
        return implode(PHP_EOL, $messages);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Formats the messages returned by Respect Validator's NestedValidationException
  *
  * Instead of returning all the messages as a simple array it maps the message to the name of the input field so
  * that way it is easier to parse the messages when they're sent back to the front end.
  *
  * Heavily inspired by NestedValidationException->getAllMessages()
  * @todo make sure $input isn't null
  * @todo handle collision in keys
  * @param NestedValidationException $exceptions
  * @return array
  */
 public function formatMessages(NestedValidationException $exceptions)
 {
     $messages = [$exceptions->getFullMessage()];
     foreach ($exceptions as $exception) {
         $input = $exception->getParams()["input"];
         $message = $exception->getMessage();
         $messages[$input] = $message;
     }
     if (count($messages) > 1) {
         array_shift($messages);
     }
     return $messages;
 }