Elgg  Version 4.3
ErrorHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
5 use Elgg\Logger;
13 
17 class ErrorHandler extends AbstractProcessingHandler {
18 
22  protected $stdout;
23 
27  protected $stderr;
28 
32  static $verbosityLevelMap = [
33  OutputInterface::VERBOSITY_QUIET => Logger::OFF,
34  OutputInterface::VERBOSITY_NORMAL => Logger::WARNING,
35  OutputInterface::VERBOSITY_VERBOSE => Logger::NOTICE,
36  OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO,
37  OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
38  ];
39 
47  public function __construct(
48  OutputInterface $stdout,
49  OutputInterface $stderr = null,
50  $bubble = true
51  ) {
52 
53  $this->stdout = $stdout;
54  $this->stderr = $stderr ? : $stdout;
55 
56  $verbosity = $this->stdout->getVerbosity() ? : OutputInterface::VERBOSITY_NORMAL;
57 
58  $level = self::$verbosityLevelMap[$verbosity];
59 
60  parent::__construct($level, $bubble);
61  }
62 
66  public function write(array $record): void {
67  $stream = $record['level'] >= Logger::ERROR ? $this->stderr : $this->stdout;
68 
69  $stream->write($record['formatted'], true);
70 
71  if ($stream instanceof StreamOutput) {
72  $dumper = new CliDumper($stream->getStream());
73  $cloner = new VarCloner();
74 
75  if (!empty($record['context'])) {
76  $dumper->dump($cloner->cloneVar($record['context']));
77  }
78 
79  if (!empty($record['extra'])) {
80  $dumper->dump($cloner->cloneVar($record['extra']));
81  }
82  }
83  }
84 
88  public function getDefaultFormatter(): FormatterInterface {
89  return new ErrorFormatter();
90  }
91 
95  public function close(): void {
96  $this->stdout = new NullOutput();
97  $this->stderr = new NullOutput();
98  }
99 }
__construct(OutputInterface $stdout, OutputInterface $stderr=null, $bubble=true)
Constructor.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
write(array $record)
{}
const OFF
Definition: Logger.php:29
Format errors for console output.
Console handler.