Skip to content

Commit

Permalink
Merge branch '5.1'
Browse files Browse the repository at this point in the history
* 5.1:
  [PhpUnitBridge] fix bad detection of unsilenced deprecations
  [Security] Unserialize $parentData, if needed, to avoid errors
  [HttpKernel] Fix error logger when stderr is redirected to /dev/null (FPM)
  • Loading branch information
nicolas-grekas committed May 19, 2020
2 parents 5fb5082 + b923991 commit b1c7383
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Expand Up @@ -105,7 +105,7 @@ public static function collectDeprecations($outputFile)
$filesStack[] = $frame['file'];
}

$deprecations[] = [error_reporting(), $msg, $file, $filesStack];
$deprecations[] = [error_reporting() & $type, $msg, $file, $filesStack];

return null;
});
Expand Down Expand Up @@ -135,7 +135,7 @@ public function handleError($type, $msg, $file, $line, $context = [])
$method = $deprecation->originatingMethod();
$msg = $deprecation->getMessage();

if (0 !== error_reporting()) {
if (error_reporting() & $type) {
$group = 'unsilenced';
} elseif ($deprecation->isLegacy()) {
$group = 'legacy';
Expand Down
Expand Up @@ -320,7 +320,7 @@ public static function handleError($type, $msg, $file, $line, $context = [])
if (\is_array($parsedMsg)) {
$msg = $parsedMsg['deprecation'];
}
if (error_reporting()) {
if (error_reporting() & $type) {
$msg = 'Unsilenced deprecation: '.$msg;
}
self::$gatheredDeprecations[] = $msg;
Expand Down
21 changes: 15 additions & 6 deletions src/Symfony/Component/HttpKernel/Log/Logger.php
Expand Up @@ -37,10 +37,10 @@ class Logger extends AbstractLogger
private $formatter;
private $handle;

public function __construct(string $minLevel = null, $output = 'php://stderr', callable $formatter = null)
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'])) {
Expand All @@ -58,7 +58,7 @@ public function __construct(string $minLevel = null, $output = 'php://stderr', c

$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));
}
}
Expand All @@ -79,10 +79,14 @@ public function log($level, $message, array $context = [])
}

$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, '{')) {
$replacements = [];
Expand All @@ -101,6 +105,11 @@ private function format(string $level, string $message, array $context): string
$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;
}
}
Expand Up @@ -68,6 +68,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->secret, $parentData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}
Expand Up @@ -26,7 +26,6 @@ class PreAuthenticatedToken extends AbstractToken
/**
* @param string|\Stringable|UserInterface $user
* @param mixed $credentials
* @param string $providerKey
* @param string[] $roles
*/
public function __construct($user, $credentials, string $providerKey, array $roles = [])
Expand Down Expand Up @@ -88,6 +87,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->credentials, $this->providerKey, $parentData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}
Expand Up @@ -101,6 +101,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->secret, $this->providerKey, $parentData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}
Expand Up @@ -54,6 +54,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->originalToken, $parentData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}
Expand Up @@ -99,6 +99,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->credentials, $this->providerKey, $parentData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}
Expand Up @@ -53,6 +53,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->user, $parentData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}
Expand Up @@ -69,6 +69,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$parentData, $this->messageKey, $this->messageData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}
Expand Up @@ -69,6 +69,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->username, $parentData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}
Expand Up @@ -83,6 +83,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->providerKey, $parentData] = $data;
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
}

0 comments on commit b1c7383

Please sign in to comment.