8 use Psr\Log\AbstractLogger;
10 use Symfony\Component\Console\Output\OutputInterface;
11 use Symfony\Component\Console\Output\ConsoleOutputInterface;
12 use Symfony\Component\Console\Helper\FormatterHelper;
51 private $formatterHelper;
58 private $initialMaxBarSize = 0;
67 private $renderedLines = 0;
74 private $lastTimeRefreshed = 0;
79 private $verbosityLevelMap = [
80 LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
81 LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
82 LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
84 LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
85 LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL,
87 LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG
93 private $formatLevelMap = [
109 private $processes = [];
120 OutputInterface $output,
121 FormatterHelper $formatterHelper,
122 array $verbosityLevelMap = [],
123 array $formatLevelMap = []
127 $this->formatterHelper = $formatterHelper;
128 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
129 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
137 if (!isset($this->verbosityLevelMap[$level])) {
142 if ($this->formatLevelMap[$level] ===
self::ERROR && $this->
output instanceof ConsoleOutputInterface) {
143 $output = $this->
output->getErrorOutput();
145 $output = $this->output;
148 if (isset($context[
'process'])) {
149 $this->registerProcess($context);
151 $this->refresh($output);
154 if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
155 $output->writeln(sprintf(
'<%1$s>%2$s</%1$s>', $this->formatLevelMap[$level],
$message));
165 private function registerProcess(array $context)
167 $name = isset($context[
'process']) ? $context[
'process'] :
'main';
168 if (!isset($this->processes[
$name])) {
169 $context[
'start'] =
time();
170 $context[
'elapsed'] = 0;
171 $this->processes[
$name] = $context;
181 private function refresh(OutputInterface $output)
183 if (!count($this->processes) || (
time() - $this->lastTimeRefreshed < 1)) {
191 foreach ($this->processes as
$name => & $process) {
192 $this->updateProcessInfo(
$name, $process);
193 $bar = $this->renderProgressBar($output, $process);
194 $maxBarSize = strlen($bar) > $maxBarSize ? strlen($bar) : $maxBarSize;
197 if (!$this->initialMaxBarSize) {
198 $this->initialMaxBarSize = $maxBarSize + 10;
201 $this->renderedLines = count($bars);
203 foreach ($bars as &$bar) {
204 if ($this->initialMaxBarSize > strlen($bar)) {
205 $bar .= str_pad(
" ", ($this->initialMaxBarSize - strlen($bar)));
209 $output->writeln(implode(
"\n", $bars));
220 private function updateProcessInfo($deployedPackagePath, array & $process)
222 $packageDeploymentInfo = $this->getPackageDeploymentInfo($deployedPackagePath .
'/info.json');
223 if ($packageDeploymentInfo) {
224 $process[
'done'] = $packageDeploymentInfo[
'count'];
226 $process[
'done'] = 0;
228 if ($process[
'done'] > $process[
'count']) {
229 $process[
'count'] = $process[
'done'];
231 if ($process[
'done'] !== $process[
'count']) {
232 $process[
'elapsed'] = $this->formatterHelper->formatTime(
time() - $process[
'start']);
234 $process[
'percent'] = floor(
235 ($process[
'count'] ? (
float)$process[
'done'] / $process[
'count'] : 0) * 100
244 private function cleanUp()
246 $this->lastTimeRefreshed =
time();
248 if ($this->renderedLines > 0) {
249 for (
$i = 0;
$i < $this->renderedLines; ++
$i) {
250 $this->
output->write(
"\x1B[1A\x1B[2K",
false, OutputInterface::OUTPUT_RAW);
253 $this->renderedLines = 0;
263 private function renderProgressBar(OutputInterface $output, array $process)
265 $title =
"{$process['process']}";
266 $titlePad = str_pad(
' ', (40 - strlen(
$title)));
267 $count =
"{$process['done']}/{$process['count']}";
268 $countPad = str_pad(
' ', (20 - strlen(
$count)));
269 $percent =
"{$process['percent']}% ";
270 $percentPad = str_pad(
' ', (7 - strlen(
$percent)));
271 return "{$title}{$titlePad}" 272 .
"{$count}{$countPad}" 273 .
"{$this->renderBar($output, $process)} " 274 .
"{$percent}%{$percentPad}" 275 .
"{$process['elapsed']} ";
285 private function renderBar(OutputInterface $output, array $process)
287 $completeBars = floor(
288 $process[
'count'] > 0 ? ($process[
'done'] / $process[
'count']) * 28 : $process[
'done'] % 28
291 $display = str_repeat(
'=', $completeBars);
292 if ($completeBars < 28) {
293 $emptyBars = 28 - $completeBars
294 - $this->formatterHelper->strlenWithoutDecoration(
$output->getFormatter(),
'>');
295 $display .=
'>' . str_repeat(
'-', $emptyBars);
output($string, $level=INFO, $label='')
if($this->helper('Magento\Tax\Helper\Data') ->displayFullSummary()) foreach( $block->getTotal() ->getFullInfo() as $info)(isset($info['hidden']) && $info['hidden']) $percent
__construct(Filesystem $filesystem, OutputInterface $output, FormatterHelper $formatterHelper, array $verbosityLevelMap=[], array $formatLevelMap=[])
const TMP_MATERIALIZATION_DIR
log($level, $message, array $context=[])
foreach( $_productCollection as $_product)() ?>" class $info
if(!isset($_GET['name'])) $name