<?php
 class vB_Utility_Exception_Phrase extends Exception { use vB_Utility_Trait_NoSerialize; protected $errors = []; public static function createFromErrorList(array $errors, $code = 0, ?Throwable $previous = null) : static { $error = array_shift($errors); $exception = new static($error, $code, $previous); foreach ($errors AS $error) { $exception->addError($error); } return $exception; } public function __construct(string|array $error, $code = 0, ?Throwable $previous = null) { $this->addError($error); parent::__construct((is_array($error) ? reset($error) : $error), $code, $previous); } public function addError(string|array $error) : void { if (!is_array($error)) { $error = [$error]; } $this->errors[] = $error; } public function hasErrors() : bool { return !empty($this->errors); } public function getErrors() : array { return $this->errors; } public function hasError(string $phraseId) : bool { if (!$this->hasErrors()) { return false; } foreach ($this->errors AS $error) { if ($error[0] == $phraseId) { return true; } } return false; } } 