errors[] = $error; $this->logger->log( $psrLogLevel, '{contextName} {message} {exception}', [ 'contextName' => $this->getErrorLoggingContextName(), 'message' => $message, 'exception' => $exception ?? '' ] ); return $this; } /** * Copies the source bag's own errors into this one without re-logging them. */ protected function copyErrorsFrom(ErrorBag $source) : void { $this->errors = \array_merge($this->errors, $source->getErrors(false, LogLevel::DEBUG)); } public function getErrors(bool $validate = false, string $minPsrLevel = LogLevel::ERROR) : array { if ($validate && !$this->validated) { $this->validated = true; $this->validate(); } return \array_values(\array_filter( $this->errors, fn($e) => $e->isPsrLevelGreaterOrEqualTo($minPsrLevel) )); } public function hasErrors(bool $validate = false, string $minPsrLevel = LogLevel::ERROR) : bool { return (\count($this->getErrors($validate, $minPsrLevel)) > 0); } public function getAllErrors(bool $validate = false, string $minPsrLevel = LogLevel::ERROR) : array { $arr = \array_values(\array_map( fn($e) => $e->getAllErrors($validate, $minPsrLevel), $this->getErrorBagChildren() )); return \array_merge($this->getErrors($validate, $minPsrLevel), ...$arr); } public function hasAnyErrors(bool $validate = false, string $minPsrLevel = LogLevel::ERROR) : bool { if ($this->hasErrors($validate, $minPsrLevel)) { return true; } foreach ($this->getErrorBagChildren() as $ch) { if ($ch->hasAnyErrors($validate, $minPsrLevel)) { return true; } } return false; } }