|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Api\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
use Closure; |
|
9
|
|
|
use Psr\Container\ContainerInterface; |
|
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
11
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
12
|
|
|
use ReflectionClass; |
|
13
|
|
|
use Yiisoft\Config\ConfigInterface; |
|
|
|
|
|
|
14
|
|
|
use Yiisoft\DataResponse\DataResponseFactoryInterface; |
|
15
|
|
|
use Yiisoft\VarDumper\VarDumper; |
|
16
|
|
|
use Yiisoft\Yii\Debug\Api\ApplicationState; |
|
17
|
|
|
use Yiisoft\Yii\Debug\Api\PhpUnitCommand; |
|
18
|
|
|
|
|
19
|
|
|
class InspectController |
|
20
|
|
|
{ |
|
21
|
|
|
public function __construct( |
|
22
|
|
|
private DataResponseFactoryInterface $responseFactory, |
|
23
|
|
|
) { |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function config(ContainerInterface $container): ResponseInterface |
|
27
|
|
|
{ |
|
28
|
|
|
$config = $container->get(ConfigInterface::class); |
|
29
|
|
|
|
|
30
|
|
|
// TODO: pass different envs |
|
31
|
|
|
$data = $config->get('web'); |
|
32
|
|
|
ksort($data); |
|
33
|
|
|
foreach ($data as &$value) { |
|
34
|
|
|
// $value = get_debug_type($value); |
|
35
|
|
|
if ($value instanceof Closure) { |
|
36
|
|
|
$value = VarDumper::create($value)->asString(); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return $this->responseFactory->createResponse($data); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function params(): ResponseInterface |
|
44
|
|
|
{ |
|
45
|
|
|
$params = ApplicationState::$params; |
|
46
|
|
|
ksort($params); |
|
47
|
|
|
|
|
48
|
|
|
return $this->responseFactory->createResponse($params); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function classes(ContainerInterface $container): ResponseInterface |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
// TODO: how to get params for console or other param groups? |
|
54
|
|
|
$classes = []; |
|
55
|
|
|
|
|
56
|
|
|
$inspected = array_merge(get_declared_classes(), get_declared_interfaces()); |
|
57
|
|
|
// TODO: think how to ignore heavy objects |
|
58
|
|
|
$patterns = [ |
|
59
|
|
|
fn (string $class) => !str_starts_with($class, 'ComposerAutoloaderInit'), |
|
60
|
|
|
fn (string $class) => !str_starts_with($class, 'Composer\\'), |
|
61
|
|
|
fn (string $class) => !str_starts_with($class, 'Yiisoft\\Yii\\Debug\\'), |
|
62
|
|
|
fn (string $class) => !str_starts_with($class, 'Yiisoft\\ErrorHandler\\ErrorHandler'), |
|
63
|
|
|
fn (string $class) => !str_contains($class, '@anonymous'), |
|
64
|
|
|
]; |
|
65
|
|
|
foreach ($patterns as $patternFunction) { |
|
66
|
|
|
$inspected = array_filter($inspected, $patternFunction); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
foreach ($inspected as $className) { |
|
70
|
|
|
$class = new ReflectionClass($className); |
|
71
|
|
|
|
|
72
|
|
|
if ($class->isInternal()) { |
|
73
|
|
|
continue; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$classes[] = $className; |
|
77
|
|
|
} |
|
78
|
|
|
sort($classes); |
|
79
|
|
|
|
|
80
|
|
|
return $this->responseFactory->createResponse($classes); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function object(ContainerInterface $container, ServerRequestInterface $request): ResponseInterface |
|
84
|
|
|
{ |
|
85
|
|
|
$request = $request->getQueryParams(); |
|
86
|
|
|
$className = $request['classname']; |
|
87
|
|
|
|
|
88
|
|
|
$class = new ReflectionClass($className); |
|
89
|
|
|
|
|
90
|
|
|
if ($class->isInternal()) { |
|
91
|
|
|
throw new InvalidArgumentException('error'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$result = VarDumper::create($container->get($className))->asString(); |
|
95
|
|
|
|
|
96
|
|
|
return $this->responseFactory->createResponse($result); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function command(ContainerInterface $container, PhpUnitCommand $command): ResponseInterface |
|
100
|
|
|
{ |
|
101
|
|
|
// TODO: pass different commands |
|
102
|
|
|
// $request = $request->getQueryParams(); |
|
103
|
|
|
// $className = $request['command']; |
|
104
|
|
|
|
|
105
|
|
|
$result = $command->run(); |
|
106
|
|
|
|
|
107
|
|
|
return $this->responseFactory->createResponse($result); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths