Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Log.php
Go to the documentation of this file.
1 <?php
7 
8 class Log
9 {
10  const GENERATION_ERROR = 1;
11 
12  const GENERATION_SUCCESS = 2;
13 
14  const COMPILATION_ERROR = 3;
15 
17 
23  protected $_successWriter;
24 
30  protected $_errorWriter;
31 
37  protected $_successEntries = [];
38 
44  protected $_errorEntries = [];
45 
50  public function __construct(Writer\Console $successWriter, Writer\Console $errorWriter)
51  {
52  $this->_successWriter = $successWriter;
53  $this->_errorWriter = $errorWriter;
54  $this->_successEntries[self::GENERATION_SUCCESS] = [];
55  $this->_errorEntries = [
56  self::CONFIGURATION_ERROR => [],
57  self::GENERATION_ERROR => [],
58  self::COMPILATION_ERROR => [],
59  ];
60  }
61 
70  public function add($type, $key, $message = '')
71  {
72  if (array_key_exists($type, $this->_successEntries)) {
73  $this->_successEntries[$type][$key][] = $message;
74  } else {
75  $this->_errorEntries[$type][$key][] = $message;
76  }
77  }
78 
85  public function report()
86  {
87  $this->_successWriter->write($this->_successEntries);
88  $this->_errorWriter->write($this->_errorEntries);
89  //do not take into account empty items since they are initialized in constructor.
90  $errors = array_filter($this->_errorEntries);
91  if (count($errors) > 0) {
92  throw new \Magento\Framework\Validator\Exception(__('Error during compilation'));
93  }
94  }
95 
101  public function hasError()
102  {
103  foreach ($this->_errorEntries as $data) {
104  if (count($data)) {
105  return true;
106  }
107  }
108  return false;
109  }
110 }
__()
Definition: __.php:13
$message
$type
Definition: item.phtml:13
add($type, $key, $message='')
Definition: Log.php:70
$errors
Definition: overview.phtml:9
__construct(Writer\Console $successWriter, Writer\Console $errorWriter)
Definition: Log.php:50