Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session inspector #128

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
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(

Check warning on line 15 in src/Controller/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/ConfigController.php#L15

Added line #L15 was not covered by tests
private DataResponseFactoryInterface $responseFactory,
) {
}

Check warning on line 18 in src/Controller/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/ConfigController.php#L18

Added line #L18 was not covered by tests

public function read(Aliases $aliases): ResponseInterface

Check warning on line 20 in src/Controller/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/ConfigController.php#L20

Added line #L20 was not covered by tests
{
$command = new BashCommand($aliases, [
'composer',
'yii-config-merge-plan',
]);
$output = $command->run()->getResult();
$mergePlanPath = substr($output, 0, strpos($output, 'Xdebug: [Step Debug]') ?: -1);

Check warning on line 27 in src/Controller/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/ConfigController.php#L22-L27

Added lines #L22 - L27 were not covered by tests

if (!file_exists($mergePlanPath)) {
throw new Exception(
sprintf(
'Could not find composer.json by the path "%s".',
$mergePlanPath,
)
);

Check warning on line 35 in src/Controller/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/ConfigController.php#L29-L35

Added lines #L29 - L35 were not covered by tests
}

$content = require $mergePlanPath;
$rootAlias = $aliases->get('@root');

Check warning on line 39 in src/Controller/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/ConfigController.php#L38-L39

Added lines #L38 - L39 were not covered by tests

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

Check warning on line 44 in src/Controller/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/ConfigController.php#L41-L44

Added lines #L41 - L44 were not covered by tests

return $this->responseFactory->createResponse($result);

Check warning on line 46 in src/Controller/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/ConfigController.php#L46

Added line #L46 was not covered by tests
}
}
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 session(ContainerInterface $container): ResponseInterface

Check warning on line 406 in src/Controller/InspectController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/InspectController.php#L406

Added line #L406 was not covered by tests
{
$session = $container->get(SessionInterface::class);
$data = $session->all();

Check warning on line 409 in src/Controller/InspectController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/InspectController.php#L408-L409

Added lines #L408 - L409 were not covered by tests

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

Check warning on line 416 in src/Controller/InspectController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/InspectController.php#L411-L416

Added lines #L411 - L416 were not covered by tests
}

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