Issues (200)

config/di.php (1 issue)

1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
use DI\Container;
15
use Monolog\Formatter\JsonFormatter;
16
use Monolog\Handler\StreamHandler;
17
use Monolog\Logger;
18
use Noodlehaus\Config;
19
use PhpProfiler\Inspector\Daemon\Reader\Worker\PhpReaderTraceLoop;
20
use PhpProfiler\Inspector\Daemon\Reader\Worker\PhpReaderTraceLoopInterface;
21
use PhpProfiler\Inspector\Output\TraceFormatter\Templated\TemplatePathResolver;
22
use PhpProfiler\Inspector\Output\TraceFormatter\Templated\TemplatePathResolverInterface;
23
use PhpProfiler\Lib\Amphp\ContextCreator;
24
use PhpProfiler\Lib\Amphp\ContextCreatorInterface;
25
use PhpProfiler\Lib\ByteStream\IntegerByteSequence\IntegerByteSequenceReader;
26
use PhpProfiler\Lib\ByteStream\IntegerByteSequence\LittleEndianReader;
27
use PhpProfiler\Lib\Elf\SymbolResolver\Elf64SymbolResolverCreator;
28
use PhpProfiler\Lib\Elf\SymbolResolver\SymbolResolverCreatorInterface;
29
use PhpProfiler\Lib\File\FileReaderInterface;
30
use PhpProfiler\Lib\File\NativeFileReader;
31
use PhpProfiler\Lib\Libc\Sys\Ptrace\Ptrace;
32
use PhpProfiler\Lib\Libc\Sys\Ptrace\PtraceX64;
33
use PhpProfiler\Lib\Log\StateCollector\CallerStateCollector;
34
use PhpProfiler\Lib\Log\StateCollector\GroupedStateCollector;
35
use PhpProfiler\Lib\Log\StateCollector\ProcessStateCollector;
36
use PhpProfiler\Lib\Log\StateCollector\StateCollector;
37
use PhpProfiler\Lib\PhpInternals\ZendTypeReader;
38
use PhpProfiler\Lib\Process\MemoryReader\MemoryReader;
39
use PhpProfiler\Lib\Process\MemoryReader\MemoryReaderInterface;
40
use PhpProfiler\Lib\Process\Search\ProcessSearcher;
41
use PhpProfiler\Lib\Process\Search\ProcessSearcherInterface;
42
use Psr\Log\LoggerInterface;
43
use function DI\autowire;
0 ignored issues
show
The function DI\autowire was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
44
45
return [
46
    MemoryReaderInterface::class => autowire(MemoryReader::class),
47
    ZendTypeReader::class => function () {
48
        return new ZendTypeReader(ZendTypeReader::V80);
49
    },
50
    SymbolResolverCreatorInterface::class => autowire(Elf64SymbolResolverCreator::class),
51
    FileReaderInterface::class => autowire(NativeFileReader::class),
52
    IntegerByteSequenceReader::class => autowire(LittleEndianReader::class),
53
    ContextCreator::class => autowire()
54
        ->constructorParameter('di_config_file', __DIR__ . '/di.php'),
55
    ContextCreatorInterface::class => autowire(ContextCreator::class)
56
        ->constructorParameter('di_config_file', __DIR__ . '/di.php'),
57
    PhpReaderTraceLoopInterface::class => autowire(PhpReaderTraceLoop::class),
58
    ProcessSearcherInterface::class => autowire(ProcessSearcher::class),
59
    Config::class => fn () => Config::load(__DIR__ . '/config.php'),
60
    TemplatePathResolverInterface::class => autowire(TemplatePathResolver::class),
61
    StateCollector::class => function (Container $container) {
62
        $collectors = [];
63
        $collectors[] = $container->make(ProcessStateCollector::class);
64
        $collectors[] = $container->make(CallerStateCollector::class);
65
        return new GroupedStateCollector(...$collectors);
66
    },
67
    LoggerInterface::class => function (Config $config) {
68
        $logger = new Logger('default');
69
        $handler = new StreamHandler(
70
            $config->get('log.path.default'),
71
            Logger::toMonologLevel($config->get('log.level'))
72
        );
73
        $handler->setFormatter(new JsonFormatter());
74
        $logger->pushHandler($handler);
75
        return $logger;
76
    },
77
    Ptrace::class => autowire(PtraceX64::class),
78
];
79