Passed
Push — semantic-logger ( 66d24d...4aff0d )
by Akihito
02:33
created

DevSemanticLoggerModule::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 10
rs 10
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\DevLogPersister;
11
use BEAR\Resource\SemanticLog\DevSemanticInvoker;
12
use BEAR\Resource\SemanticLog\Profile\Verbose\ContextFactory;
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 log persister with configurable directory
51
        $this->bind(DevLogPersister::class)->to(DevLogPersister::class)->in(Scope::SINGLETON);
52
        $this->bind()->annotatedWith('dev_log_directory')->toInstance($this->logDirectory);
53
54
        // Bind the original invoker with annotation so our dev invoker can inject it
55
        $this->bind(InvokerInterface::class)->annotatedWith('original')->to(Invoker::class);
56
57
        // Override the default invoker with our dev semantic invoker
58
        $this->bind(InvokerInterface::class)->to(DevSemanticInvoker::class);
59
    }
60
}
61