Merge branch '5.1' into 5.2

* 5.1:
  [Uid] fix checking for valid UUIDs
  [HttpKernel] Configure the ErrorHandler even when it is overriden
  Allow relative path to composer cache
This commit is contained in:
Nicolas Grekas 2021-01-25 14:54:05 +01:00
commit c11a6da08c
5 changed files with 40 additions and 16 deletions

View File

@ -164,6 +164,18 @@ $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar')
? ('#!/usr/bin/env php' === file_get_contents($COMPOSER, false, null, 0, 18) ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
: 'composer';
$prevCacheDir = getenv('COMPOSER_CACHE_DIR');
if ($prevCacheDir) {
if (false === $absoluteCacheDir = realpath($prevCacheDir)) {
@mkdir($prevCacheDir, 0777, true);
$absoluteCacheDir = realpath($prevCacheDir);
}
if ($absoluteCacheDir) {
putenv("COMPOSER_CACHE_DIR=$absoluteCacheDir");
} else {
$prevCacheDir = false;
}
}
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : ''));
$configurationHash = md5(implode(\PHP_EOL, [md5_file(__FILE__), $SYMFONY_PHPUNIT_REMOVE, (int) $PHPUNIT_REMOVE_RETURN_TYPEHINT]));
$PHPUNIT_VERSION_DIR = sprintf('phpunit-%s-%d', $PHPUNIT_VERSION, $PHPUNIT_REMOVE_RETURN_TYPEHINT);
@ -246,6 +258,9 @@ if (!file_exists("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR/phpunit") || $configurationH
// --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS
$exit = proc_close(proc_open("$q$COMPOSER install --no-dev --prefer-dist --no-progress $q", [], $p, getcwd()));
putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
if ($prevCacheDir) {
putenv("COMPOSER_CACHE_DIR=$prevCacheDir");
}
if ($exit) {
exit($exit);
}

View File

@ -30,6 +30,7 @@ use Symfony\Component\HttpKernel\KernelEvents;
*/
class DebugHandlersListener implements EventSubscriberInterface
{
private $earlyHandler;
private $exceptionHandler;
private $logger;
private $deprecationLogger;
@ -51,6 +52,10 @@ class DebugHandlersListener implements EventSubscriberInterface
*/
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = \E_ALL, ?int $throwAt = \E_ALL, bool $scream = true, $fileLinkFormat = null, bool $scope = true, LoggerInterface $deprecationLogger = null)
{
$handler = set_exception_handler('var_dump');
$this->earlyHandler = \is_array($handler) ? $handler[0] : null;
restore_exception_handler();
$this->exceptionHandler = $exceptionHandler;
$this->logger = $logger;
$this->levels = null === $levels ? \E_ALL : $levels;
@ -78,6 +83,10 @@ class DebugHandlersListener implements EventSubscriberInterface
$handler = \is_array($handler) ? $handler[0] : null;
restore_exception_handler();
if (!$handler instanceof ErrorHandler) {
$handler = $this->earlyHandler;
}
if ($handler instanceof ErrorHandler) {
if ($this->logger || $this->deprecationLogger) {
$this->setDefaultLoggers($handler);

View File

@ -40,7 +40,7 @@ class BinaryUtil
// 0x01b21dd213814000 is the number of 100-ns intervals between the
// UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
private const TIME_OFFSET_INT = 0x01b21dd213814000;
private const TIME_OFFSET_COM = "\xfe\x4d\xe2\x2d\xec\x7e\xc0\x00";
private const TIME_OFFSET_COM2 = "\xfe\x4d\xe2\x2d\xec\x7e\xc0\x00";
public static function toBase(string $bytes, array $map): string
{
@ -121,9 +121,15 @@ class BinaryUtil
}
$time = str_pad(hex2bin($time), 8, "\0", \STR_PAD_LEFT);
$time = self::add($time, self::TIME_OFFSET_COM);
$time[0] = $time[0] & "\x7F";
$time = self::add($time, self::TIME_OFFSET_COM2);
return self::toBase($time, self::BASE10) / 10000000;
if ($time >= self::TIME_OFFSET_COM2) {
$time = -1 * self::toBase($time ^ "\xff\xff\xff\xff\xff\xff\xff\xff", self::BASE10);
} else {
$time[0] = $time[0] & "\x7F";
$time = self::toBase($time, self::BASE10);
}
return $time / 10000000;
}
}

View File

@ -153,7 +153,7 @@ class Ulid extends AbstractUid
if (\PHP_INT_SIZE >= 8) {
$time = base_convert($time, 10, 32);
} else {
$time = bin2hex(BinaryUtil::fromBase($time, BinaryUtil::BASE10));
$time = str_pad(bin2hex(BinaryUtil::fromBase($time, BinaryUtil::BASE10)), 12, '0', \STR_PAD_LEFT);
$time = sprintf('%s%04s%04s',
base_convert(substr($time, 0, 2), 16, 32),
base_convert(substr($time, 2, 5), 16, 32),

View File

@ -22,11 +22,7 @@ class Uuid extends AbstractUid
public function __construct(string $uuid)
{
try {
$type = uuid_type($uuid);
} catch (\ValueError $e) {
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid), 0, $e);
}
$type = uuid_is_valid($uuid) ? uuid_type($uuid) : false;
if (false === $type || \UUID_TYPE_INVALID === $type || (static::TYPE ?: $type) !== $type) {
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid));
@ -59,13 +55,11 @@ class Uuid extends AbstractUid
return new static($uuid);
}
try {
$type = uuid_type($uuid);
} catch (\ValueError $e) {
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid), 0, $e);
if (!uuid_is_valid($uuid)) {
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid));
}
switch ($type) {
switch (uuid_type($uuid)) {
case UuidV1::TYPE: return new UuidV1($uuid);
case UuidV3::TYPE: return new UuidV3($uuid);
case UuidV4::TYPE: return new UuidV4($uuid);
@ -114,7 +108,7 @@ class Uuid extends AbstractUid
return uuid_is_valid($uuid);
}
return static::TYPE === uuid_type($uuid);
return uuid_is_valid($uuid) && static::TYPE === uuid_type($uuid);
}
public function toBinary(): string