From 911877ccf7d9059d4d29a3ce94d6119ea13e1ad2 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 28 Dec 2024 17:42:56 +0300 Subject: [PATCH] Remove `yiisoft/aliases` dependency (#293) --- composer.json | 1 - config/di.php | 17 +++++++++++++++-- tests/Unit/Storage/FileStorageTest.php | 6 +----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index cf6c2f09..feb6f061 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,6 @@ "psr/log": "^1.0|^2.0|^3.0", "symfony/console": "^5.4|^6.0", "symfony/var-dumper": "^5.4|^6.4", - "yiisoft/aliases": "^3.0", "yiisoft/arrays": "^2.0|^3.0", "yiisoft/config": "^1.3", "yiisoft/di": "^1.0", diff --git a/config/di.php b/config/di.php index 7d34518b..a0d40ec2 100644 --- a/config/di.php +++ b/config/di.php @@ -21,11 +21,24 @@ */ $common = [ - StorageInterface::class => static function (ContainerInterface $container, Aliases $aliases) use ($params) { + StorageInterface::class => static function (ContainerInterface $container, ?Aliases $aliases = null) use ($params) { $params = $params['yiisoft/yii-debug']; $debuggerIdGenerator = $container->get(DebuggerIdGenerator::class); $excludedClasses = $params['dumper.excludedClasses']; - $fileStorage = new FileStorage($aliases->get($params['path']), $debuggerIdGenerator, $excludedClasses); + + $path = $params['path']; + if (str_starts_with($path, '@')) { + if ($aliases === null) { + throw new LogicException( + sprintf( + 'yiisoft/aliases dependency is required to resolve path "%s".', + $path + ) + ); + } + $path = $aliases->get($path); + } + $fileStorage = new FileStorage($path, $debuggerIdGenerator, $excludedClasses); if (isset($params['historySize'])) { $fileStorage->setHistorySize((int) $params['historySize']); diff --git a/tests/Unit/Storage/FileStorageTest.php b/tests/Unit/Storage/FileStorageTest.php index 537a9bce..1ca32225 100644 --- a/tests/Unit/Storage/FileStorageTest.php +++ b/tests/Unit/Storage/FileStorageTest.php @@ -4,7 +4,6 @@ namespace Yiisoft\Yii\Debug\Tests\Unit\Storage; -use Yiisoft\Aliases\Aliases; use Yiisoft\Files\FileHelper; use Yiisoft\Yii\Debug\DebuggerIdGenerator; use Yiisoft\Yii\Debug\Storage\FileStorage; @@ -79,9 +78,6 @@ public function testClear(array $data): void public function getStorage(DebuggerIdGenerator $idGenerator): FileStorage { - return new FileStorage( - (new Aliases())->get($this->path), - $idGenerator, - ); + return new FileStorage($this->path, $idGenerator); } }