Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ConsoleLogger.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Console\Logger;
013
014 use Psr\Log\AbstractLogger;
015 use Psr\Log\InvalidArgumentException;
016 use Psr\Log\LogLevel;
017 use Symfony\Component\Console\Output\ConsoleOutputInterface;
018 use Symfony\Component\Console\Output\OutputInterface;
019
020 /**
021 * PSR-3 compliant console logger.
022 *
023 * @author Kévin Dunglas <dunglas@gmail.com>
024 *
025 * @see https://www.php-fig.org/psr/psr-3/
026 */
027 class ConsoleLogger extends AbstractLogger
028 {
029 const INFO = 'info';
030 const ERROR = 'error';
031
032 private $output;
033 private $verbosityLevelMap = [
034 LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
035 LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
036 LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
037 LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
038 LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
039 LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
040 LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
041 LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG,
042 ];
043 private $formatLevelMap = [
044 LogLevel::EMERGENCY => self::ERROR,
045 LogLevel::ALERT => self::ERROR,
046 LogLevel::CRITICAL => self::ERROR,
047 LogLevel::ERROR => self::ERROR,
048 LogLevel::WARNING => self::INFO,
049 LogLevel::NOTICE => self::INFO,
050 LogLevel::INFO => self::INFO,
051 LogLevel::DEBUG => self::INFO,
052 ];
053 private $errored = false;
054
055 public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = [])
056 {
057 $this->output = $output;
058 $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
059 $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
060 }
061
062 /**
063 * {@inheritdoc}
064 */
065 public function log($level, $message, array $context = [])
066 {
067 if (!isset($this->verbosityLevelMap[$level])) {
068 throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
069 }
070
071 $output = $this->output;
072
073 // Write to the error output if necessary and available
074 if (self::ERROR === $this->formatLevelMap[$level]) {
075 if ($this->output instanceof ConsoleOutputInterface) {
076 $output = $output->getErrorOutput();
077 }
078 $this->errored = true;
079 }
080
081 // the if condition check isn't necessary -- it's the same one that $output will do internally anyway.
082 // We only do it for efficiency here as the message formatting is relatively expensive.
083 if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
084 $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)), $this->verbosityLevelMap[$level]);
085 }
086 }
087
088 /**
089 * Returns true when any messages have been logged at error levels.
090 *
091 * @return bool
092 */
093 public function hasErrored()
094 {
095 return $this->errored;
096 }
097
098 /**
099 * Interpolates context values into the message placeholders.
100 *
101 * @author PHP Framework Interoperability Group
102 *
103 * @param string $message
104 *
105 * @return string
106 */
107 private function interpolate($message, array $context)
108 {
109 if (false === strpos($message, '{')) {
110 return $message;
111 }
112
113 $replacements = [];
114 foreach ($context as $key => $val) {
115 if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {
116 $replacements["{{$key}}"] = $val;
117 } elseif ($val instanceof \DateTimeInterface) {
118 $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339);
119 } elseif (\is_object($val)) {
120 $replacements["{{$key}}"] = '[object '.\get_class($val).']';
121 } else {
122 $replacements["{{$key}}"] = '['.\gettype($val).']';
123 }
124 }
125
126 return strtr($message, $replacements);
127 }
128 }
129