| 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 |  |  |  |