From 36bd562ab13ea288359281eaf3f56f6e967277a4 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sun, 8 Oct 2023 13:40:19 +0300 Subject: [PATCH 1/3] Add merge plan view action --- config/routes.php | 3 ++ src/Controller/ConfigController.php | 47 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/Controller/ConfigController.php diff --git a/config/routes.php b/config/routes.php index 7fd5827..3e87dbd 100644 --- a/config/routes.php +++ b/config/routes.php @@ -116,6 +116,9 @@ static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $ Route::post('/curl/build') ->action([InspectController::class, 'buildCurl']) ->name('curl/build'), + Route::get('/config/merge-plan') + ->action([\Yiisoft\Yii\Debug\Api\Controller\ConfigController::class, 'read']) + ->name('config/merge-plan'), Group::create('/git') ->namePrefix('/git') ->routes( diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php new file mode 100644 index 0000000..40be194 --- /dev/null +++ b/src/Controller/ConfigController.php @@ -0,0 +1,47 @@ +run()->getResult(); + $mergePlanPath = substr($output, 0, strpos($output, "Xdebug: [Step Debug]") ?: -1); + + if (!file_exists($mergePlanPath)) { + throw new Exception( + sprintf( + 'Could not find composer.json by the path "%s".', + $mergePlanPath, + ) + ); + } + + $content = require $mergePlanPath; + + $result = [ + 'path' => $mergePlanPath, + 'data' => $content, + ]; + + return $this->responseFactory->createResponse($result); + } +} From 4e78d9169c1fbd7e71d063c7d1ad5ddc19d9034e Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 8 Oct 2023 10:40:36 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- src/Controller/ConfigController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php index 40be194..49f3c38 100644 --- a/src/Controller/ConfigController.php +++ b/src/Controller/ConfigController.php @@ -24,7 +24,7 @@ public function read(Aliases $aliases): ResponseInterface 'yii-config-merge-plan', ]); $output = $command->run()->getResult(); - $mergePlanPath = substr($output, 0, strpos($output, "Xdebug: [Step Debug]") ?: -1); + $mergePlanPath = substr($output, 0, strpos($output, 'Xdebug: [Step Debug]') ?: -1); if (!file_exists($mergePlanPath)) { throw new Exception( From 7aa5e74c7b6725d129a3c441d4aeb4afeb7b06b8 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sun, 8 Oct 2023 14:04:16 +0300 Subject: [PATCH 3/3] Remove absolute path --- src/Controller/ConfigController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php index 49f3c38..cfe1407 100644 --- a/src/Controller/ConfigController.php +++ b/src/Controller/ConfigController.php @@ -36,9 +36,10 @@ public function read(Aliases $aliases): ResponseInterface } $content = require $mergePlanPath; + $rootAlias = $aliases->get('@root'); $result = [ - 'path' => $mergePlanPath, + 'path' => substr($mergePlanPath, strlen($rootAlias) + 1), 'data' => $content, ];