Update to laravel 7

This commit is contained in:
KodeStar
2022-03-10 11:54:29 +00:00
parent 61a5a1a8b0
commit f9a19fce91
7170 changed files with 274189 additions and 283773 deletions

View File

@@ -22,7 +22,7 @@ use Psr\Log\LogLevel;
*/
class Logger extends AbstractLogger
{
private static $levels = [
private const LEVELS = [
LogLevel::DEBUG => 0,
LogLevel::INFO => 1,
LogLevel::NOTICE => 2,
@@ -35,15 +35,20 @@ class Logger extends AbstractLogger
private $minLevelIndex;
private $formatter;
/** @var resource|null */
private $handle;
public function __construct(string $minLevel = null, $output = 'php://stderr', callable $formatter = null)
/**
* @param string|resource|null $output
*/
public function __construct(string $minLevel = null, $output = null, callable $formatter = null)
{
if (null === $minLevel) {
$minLevel = 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::CRITICAL : LogLevel::WARNING;
$minLevel = null === $output || 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::ERROR : LogLevel::WARNING;
if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) {
switch ((int) (isset($_ENV['SHELL_VERBOSITY']) ? $_ENV['SHELL_VERBOSITY'] : $_SERVER['SHELL_VERBOSITY'])) {
switch ((int) ($_ENV['SHELL_VERBOSITY'] ?? $_SERVER['SHELL_VERBOSITY'])) {
case -1: $minLevel = LogLevel::ERROR; break;
case 1: $minLevel = LogLevel::NOTICE; break;
case 2: $minLevel = LogLevel::INFO; break;
@@ -52,37 +57,43 @@ class Logger extends AbstractLogger
}
}
if (!isset(self::$levels[$minLevel])) {
if (!isset(self::LEVELS[$minLevel])) {
throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $minLevel));
}
$this->minLevelIndex = self::$levels[$minLevel];
$this->minLevelIndex = self::LEVELS[$minLevel];
$this->formatter = $formatter ?: [$this, 'format'];
if (false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) {
if ($output && false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) {
throw new InvalidArgumentException(sprintf('Unable to open "%s".', $output));
}
}
/**
* {@inheritdoc}
*
* @return void
*/
public function log($level, $message, array $context = [])
{
if (!isset(self::$levels[$level])) {
if (!isset(self::LEVELS[$level])) {
throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
}
if (self::$levels[$level] < $this->minLevelIndex) {
if (self::LEVELS[$level] < $this->minLevelIndex) {
return;
}
$formatter = $this->formatter;
fwrite($this->handle, $formatter($level, $message, $context));
if ($this->handle) {
@fwrite($this->handle, $formatter($level, $message, $context));
} else {
error_log($formatter($level, $message, $context, false));
}
}
private function format(string $level, string $message, array $context): string
private function format(string $level, string $message, array $context, bool $prefixDate = true): string
{
if (false !== strpos($message, '{')) {
if (str_contains($message, '{')) {
$replacements = [];
foreach ($context as $key => $val) {
if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {
@@ -99,6 +110,11 @@ class Logger extends AbstractLogger
$message = strtr($message, $replacements);
}
return sprintf('%s [%s] %s', date(\DateTime::RFC3339), $level, $message).\PHP_EOL;
$log = sprintf('[%s] %s', $level, $message).\PHP_EOL;
if ($prefixDate) {
$log = date(\DateTime::RFC3339).' '.$log;
}
return $log;
}
}