Passed
Pull Request — 1.x (#334)
by Akihito
02:32
created

DevSemanticLoggerModule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 31
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A configure() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\SemanticLog\Module;
6
7
use BEAR\Resource\Invoker;
8
use BEAR\Resource\InvokerInterface;
9
use BEAR\Resource\SemanticLog\ContextFactoryInterface;
10
use BEAR\Resource\SemanticLog\DevSemanticInvoker;
11
use BEAR\Resource\SemanticLog\Profile\Verbose\ContextFactory;
12
use Koriym\SemanticLogger\DevLogger;
13
use Koriym\SemanticLogger\SemanticLogger;
14
use Koriym\SemanticLogger\SemanticLoggerInterface;
15
use Override;
16
use Ray\Di\AbstractModule;
17
use Ray\Di\Scope;
18
19
use function sys_get_temp_dir;
20
21
/**
22
 * Development semantic logging module with file persistence
23
 *
24
 * Provides immediate log file writing for MCP server integration and AI-assisted debugging.
25
 * Uses Verbose Profile system with complete XHProf, Xdebug, and PHP backtrace data.
26
 */
27
final class DevSemanticLoggerModule extends AbstractModule
28
{
29
    public function __construct(
30
        private string $logDirectory = '',
31
    ) {
32
        parent::__construct();
33
34
        if ($this->logDirectory !== '') {
35
            return;
36
        }
37
38
        $this->logDirectory = sys_get_temp_dir();
39
    }
40
41
    #[Override]
42
    protected function configure(): void
43
    {
44
        // Use Verbose Context Factory for complete Profile data
45
        $this->bind(ContextFactoryInterface::class)->to(ContextFactory::class)->in(Scope::SINGLETON);
46
47
        // Semantic logger
48
        $this->bind(SemanticLoggerInterface::class)->to(SemanticLogger::class)->in(Scope::SINGLETON);
49
50
        // Dev logger with configurable directory
51
        $this->bind(DevLogger::class)->toInstance(new DevLogger($this->logDirectory))->in(Scope::SINGLETON);
52
53
        // Bind the original invoker with annotation so our dev invoker can inject it
54
        $this->bind(InvokerInterface::class)->annotatedWith('original')->to(Invoker::class);
55
56
        // Override the default invoker with our dev semantic invoker
57
        $this->bind(InvokerInterface::class)->to(DevSemanticInvoker::class);
58
    }
59
}
60