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

Add opcache page #147

Merged
merged 11 commits into from
Jul 6, 2024
Merged
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
5 changes: 4 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
"Yiisoft\\Db\\Connection\\ConnectionInterface",
"Yiisoft\\Db\\Query\\Query",
"Yiisoft\\Yii\\Debug\\Collector\\RequestCollector",
"Yiisoft\\Yii\\Http\\Application",
"posix_getgrgid",
"posix_getpwuid"
"posix_getpwuid",
"opcache_get_status",
"opcache_get_configuration"
]
}
8 changes: 8 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Yiisoft\Yii\Debug\Api\Inspector\Controller\ComposerController;
use Yiisoft\Yii\Debug\Api\Inspector\Controller\GitController;
use Yiisoft\Yii\Debug\Api\Inspector\Controller\InspectController;
use Yiisoft\Yii\Debug\Api\Inspector\Controller\OpcacheController;
use Yiisoft\Yii\Middleware\CorsAllowAll;
use Yiisoft\Yii\Middleware\IpFilter;

Expand Down Expand Up @@ -171,5 +172,12 @@ static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $
->action([CacheController::class, 'clear'])
->name('/clear'),
),
Group::create('/opcache')
->namePrefix('opcache')
->routes(
Route::get('[/]')
->action([OpcacheController::class, 'index'])
->name('/index'),
),
),
];
19 changes: 12 additions & 7 deletions src/Debug/Http/HttpApplicationWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@ public function __construct(
) {
}

/**
* @psalm-suppress UndefinedClass
*/
public function wrap(Application $application): void
{
$middlewareDispatcher = $this->middlewareDispatcher;
$middlewareDefinitions = $this->middlewareDefinitions;

$closure = Closure::bind(static function (Application $application) use (
$middlewareDispatcher,
$middlewareDefinitions,
) {
$application->dispatcher = $middlewareDispatcher->withMiddlewares([
$closure = Closure::bind(
/**
* @psalm-suppress UndefinedClass
*/
static fn (Application $application) => $application->dispatcher = $middlewareDispatcher->withMiddlewares([
...$middlewareDefinitions,
['class' => MiddlewareDispatcherMiddleware::class, '$middlewareDispatcher' => $application->dispatcher],
]);
}, null, $application);
]),
null,
$application
);

$closure($application);
}
Expand Down
17 changes: 13 additions & 4 deletions src/Debug/Provider/DebugApiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
return [];
}

/**
* @psalm-suppress UndefinedClass
*/
public function getExtensions(): array
{
return [
$extensions = [
RouteCollectorInterface::class => static function (
ContainerInterface $container,
RouteCollectorInterface $routeCollector
Expand All @@ -36,12 +39,18 @@

return $routeCollector;
},
Application::class => static function (ContainerInterface $container, Application $application) {
];
if (class_exists(Application::class)) {
$extensions[Application::class] = static function (
ContainerInterface $container,
Application $application

Check failure on line 46 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:46:17: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 46 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:46:17: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)
): Application {

Check failure on line 47 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:47:16: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 47 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:47:16: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)
$applicationWrapper = $container->get(HttpApplicationWrapper::class);
$applicationWrapper->wrap($application);

return $application;
},
];
};
}
return $extensions;
}
}
31 changes: 31 additions & 0 deletions src/Inspector/Controller/OpcacheController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Api\Inspector\Controller;

use Psr\Http\Message\ResponseInterface;
use Yiisoft\DataResponse\DataResponseFactoryInterface;
use Yiisoft\Http\Status;

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

public function index(): ResponseInterface
{
if (!\function_exists('opcache_get_status') || ($status = \opcache_get_status(true)) === false) {
return $this->responseFactory->createResponse([
'message' => 'OPcache is not installed or configured',
], Status::UNPROCESSABLE_ENTITY);
}

return $this->responseFactory->createResponse([
'status' => $status,
'configuration' => \opcache_get_configuration(),
]);
}
}
6 changes: 3 additions & 3 deletions src/ServerSentEventsStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function detach(): void
$this->eof = true;
}

public function getSize()
public function getSize(): int
{
return null;
return 0;
}

public function tell(): int
Expand Down Expand Up @@ -62,7 +62,7 @@ public function isWritable(): bool
return false;
}

public function write($string): void
public function write($string): int
{
throw new \RuntimeException('Stream is not writable');
}
Expand Down
Loading