Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $
Route::get('/events')
->action([InspectController::class, 'eventListeners'])
->name('events'),
Route::get('/session')
->action([InspectController::class, 'session'])
->name('session'),
Route::get('/params')
->action([InspectController::class, 'params'])
->name('params'),
Expand Down Expand Up @@ -116,6 +119,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(
Expand Down
48 changes: 48 additions & 0 deletions src/Controller/ConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Api\Controller;

use Exception;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\Aliases\Aliases;
use Yiisoft\DataResponse\DataResponseFactoryInterface;
use Yiisoft\Yii\Debug\Api\Inspector\Command\BashCommand;

final class ConfigController
{
public function __construct(
private DataResponseFactoryInterface $responseFactory,
) {
}

public function read(Aliases $aliases): ResponseInterface
{
$command = new BashCommand($aliases, [
'composer',
'yii-config-merge-plan',
]);
$output = $command->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;
$rootAlias = $aliases->get('@root');

$result = [
'path' => substr($mergePlanPath, strlen($rootAlias) + 1),
'data' => $content,
];

return $this->responseFactory->createResponse($result);
}
}
14 changes: 14 additions & 0 deletions src/Controller/InspectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Yiisoft\Router\CurrentRoute;
use Yiisoft\Router\RouteCollectionInterface;
use Yiisoft\Router\UrlMatcherInterface;
use Yiisoft\Session\SessionInterface;
use Yiisoft\Translator\CategorySource;
use Yiisoft\VarDumper\VarDumper;
use Yiisoft\Yii\Debug\Api\Inspector\ApplicationState;
Expand Down Expand Up @@ -402,6 +403,19 @@ public function eventListeners(ContainerInterface $container)
]);
}

public function session(ContainerInterface $container): ResponseInterface
{
$session = $container->get(SessionInterface::class);
$data = $session->all();

return $this->responseFactory->createResponse([
'id' => $session->getId(),
'name' => $session->getName(),
'cookieParameters' => $session->getCookieParameters(),
'data' => $data,
]);
}

public function buildCurl(
ServerRequestInterface $request,
CollectorRepositoryInterface $collectorRepository
Expand Down