Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExceptionCollector.php
Go to the documentation of this file.
1 <?php
7 
9 {
15  private $errors = [];
16 
24  public function addError($filename, $message)
25  {
26  $error[$filename] = $message;
27  $this->errors = array_merge_recursive($this->errors, $error);
28  }
29 
36  public function throwException()
37  {
38  if (empty($this->errors)) {
39  return;
40  }
41 
42  $errorMsg = implode("\n\n", $this->formatErrors($this->errors));
43  throw new \Exception("\n" . $errorMsg);
44  }
45 
53  private function formatErrors($errors)
54  {
55  $flattenedErrors = [];
56  foreach ($errors as $key => $errorMsg) {
57  if (is_array($errorMsg)) {
58  $flattenedErrors = array_merge($flattenedErrors, $this->formatErrors($errorMsg));
59  continue;
60  }
61 
62  $flattenedErrors[] = $errorMsg;
63  }
64 
65  return $flattenedErrors;
66  }
67 }
$message