| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace SetBased\Audit\MySql\Metadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SetBased\Audit\Metadata\ColumnMetadata as BaseColumnMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Metadata of table columns. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | class ColumnMetadata extends BaseColumnMetadata | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |   //-------------------------------------------------------------------------------------------------------------------- | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |   /** | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |    * The properties of the column that are stored by this class. | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |    * | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |    * var string[] | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |   protected static array $fields = ['column_name', | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |                                     'column_type', | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |                                     'is_nullable', | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |                                     'character_set_name', | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |                                     'collation_name']; | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |   //-------------------------------------------------------------------------------------------------------------------- | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |   /** | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |    * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 | 27 |  |   public function getColumnAuditDefinition(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |   { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 | 27 |  |     $parts = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 | 27 |  |     if ($this->getProperty('column_type')!==null) | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 | 27 |  |       $parts[] = $this->getProperty('column_type'); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 | 27 |  |     if ($this->getProperty('character_set_name')!==null) | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 21 |  |       $parts[] = 'character set '.$this->getProperty('character_set_name'); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 | 27 |  |     if ($this->getProperty('collation_name')!==null) | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 | 21 |  |       $parts[] = 'collate '.$this->getProperty('collation_name'); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 | 27 |  |     $parts[] = ($this->getProperty('is_nullable')==='YES') ? 'null' : 'not null'; | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 | 27 |  |     if ($this->getProperty('column_default')!==null && $this->getProperty('column_default')!=='NULL') | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 2 |  |       $parts[] = 'default '.$this->getProperty('column_default'); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 27 |  |     elseif ($this->getProperty('column_type')==='timestamp' && $this->getProperty('is_nullable')==='YES') | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |       // Prevent automatic updates of timestamp columns. | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 4 |  |       $parts[] = 'default null'; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 27 |  |     return implode(' ', $parts); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |   } | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |   //-------------------------------------------------------------------------------------------------------------------- | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |   /** | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |    * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 67 | 6 |  |   public function getColumnDefinition(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |   { | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 6 |  |     $parts = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 | 6 |  |     if ($this->getProperty('column_type')!==null) | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 6 |  |       $parts[] = $this->getProperty('column_type'); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 76 | 6 |  |     if ($this->getProperty('character_set_name')!==null) | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 78 | 4 |  |       $parts[] = 'character set '.$this->getProperty('character_set_name'); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 | 6 |  |     if ($this->getProperty('collation_name')!==null) | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 83 | 4 |  |       $parts[] = 'collate '.$this->getProperty('collation_name'); | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 86 | 6 |  |     $parts[] = ($this->getProperty('is_nullable')==='YES') ? 'null' : 'not null'; | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 88 | 6 |  |     if ($this->getProperty('column_default')!==null && $this->getProperty('column_default')!=='NULL') | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |       $parts[] = 'default '.$this->getProperty('column_default'); | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 | 6 |  |     return implode(' ', $parts); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |   } | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |   //-------------------------------------------------------------------------------------------------------------------- | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |   /** | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |    * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 100 | 6 |  |   public function getTypeInfo1(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |   { | 
            
                                                                        
                            
            
                                    
            
            
                | 102 | 6 |  |     if ($this->getProperty('is_nullable')==='YES') | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 104 | 6 |  |       return $this->getProperty('column_type'); | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |     return $this->getProperty('column_type').' not null'; | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |   } | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |   //-------------------------------------------------------------------------------------------------------------------- | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |   /** | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |    * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 6 |  |   public function getTypeInfo2(): ?string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |   { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 6 |  |     if ($this->getProperty('collation_name')!==null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 4 |  |       return sprintf('[%s] [%s]', $this->getProperty('character_set_name'), $this->getProperty('collation_name')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 121 | 6 |  |     return null; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 122 |  |  |   } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                        
                                                                
            
                                    
            
            
                | 124 |  |  |   //-------------------------------------------------------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 127 |  |  | //---------------------------------------------------------------------------------------------------------------------- | 
            
                                                        
            
                                    
            
            
                | 128 |  |  |  |