| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace WebStream\Annotation\Attributes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use WebStream\Annotation\Base\Annotation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use WebStream\Annotation\Base\IAnnotatable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use WebStream\Annotation\Base\IRead; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use WebStream\Annotation\Base\IClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use WebStream\Container\Container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use WebStream\Exception\Extend\DatabaseException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use WebStream\IO\File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * Database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author Ryuichi TANAKA. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @since 2013/12/07 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @version 0.7 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @Annotation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @Target("CLASS") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class Database extends Annotation implements IClass, IRead | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var array<string> 注入アノテーション情報 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $injectAnnotation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var array<string> 読み込みアノテーション情報 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     private $readAnnotation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function onInject(array $injectAnnotation) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->injectAnnotation = $injectAnnotation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->readAnnotation = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     public function getAnnotationInfo(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return $this->readAnnotation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     public function onClassInject(IAnnotatable $instance, \ReflectionClass $class, Container $container) | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $driver = $this->injectAnnotation['driver']; | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         $config = $this->injectAnnotation['config']; | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         if (!class_exists($driver)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             throw new DatabaseException("Database driver is undefined:" . $driver); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $file = new File($container->rootPath . '/' . $config); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $this->readAnnotation['filepath'] = $class->getFileName(); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $this->readAnnotation['configPath'] = $file->getAbsoluteFilePath(); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         $this->readAnnotation['driverClassPath'] = $driver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |  |