1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Module\Di\Compiler\Log;
class Log
{
const GENERATION_ERROR = 1;
const GENERATION_SUCCESS = 2;
const COMPILATION_ERROR = 3;
const CONFIGURATION_ERROR = 4;
/**
* Success log writer
*
* @var Writer\Console
*/
protected $_successWriter;
/**
* Error log writer
*
* @var Writer\Console
*/
protected $_errorWriter;
/**
* List of success log entries
*
* @var array
*/
protected $_successEntries = [];
/**
* List of error entries
*
* @var array
*/
protected $_errorEntries = [];
/**
* @param Writer\Console $successWriter
* @param Writer\Console $errorWriter
*/
public function __construct(Writer\Console $successWriter, Writer\Console $errorWriter)
{
$this->_successWriter = $successWriter;
$this->_errorWriter = $errorWriter;
$this->_successEntries[self::GENERATION_SUCCESS] = [];
$this->_errorEntries = [
self::CONFIGURATION_ERROR => [],
self::GENERATION_ERROR => [],
self::COMPILATION_ERROR => [],
];
}
/**
* Add log message
*
* @param string $type
* @param string $key
* @param string $message
* @return void
*/
public function add($type, $key, $message = '')
{
if (array_key_exists($type, $this->_successEntries)) {
$this->_successEntries[$type][$key][] = $message;
} else {
$this->_errorEntries[$type][$key][] = $message;
}
}
/**
* Write entries
*
* @return void
* @throws \Magento\Framework\Validator\Exception
*/
public function report()
{
$this->_successWriter->write($this->_successEntries);
$this->_errorWriter->write($this->_errorEntries);
//do not take into account empty items since they are initialized in constructor.
$errors = array_filter($this->_errorEntries);
if (count($errors) > 0) {
throw new \Magento\Framework\Validator\Exception(__('Error during compilation'));
}
}
/**
* Check whether error exists
*
* @return bool
*/
public function hasError()
{
foreach ($this->_errorEntries as $data) {
if (count($data)) {
return true;
}
}
return false;
}
}