| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Doctrine\Migrations\Configuration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Doctrine\Migrations\Configuration\Exception\XmlNotValid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use DOMDocument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use const DIRECTORY_SEPARATOR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use const LIBXML_NOCDATA; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use function libxml_clear_errors; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use function libxml_use_internal_errors; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use function simplexml_load_file; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class XmlConfiguration extends AbstractFileConfiguration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 17 |  |  |     /** @inheritdoc */ | 
            
                                                                        
                            
            
                                    
            
            
                | 18 | 19 |  |     protected function doLoad(string $file) : void | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 | 19 |  |         libxml_use_internal_errors(true); | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 | 19 |  |         $xml = new DOMDocument(); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 | 19 |  |         $xml->load($file); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 | 19 |  |         $xsdPath = __DIR__ . DIRECTORY_SEPARATOR . 'XML' . DIRECTORY_SEPARATOR . 'configuration.xsd'; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 | 19 |  |         if (! $xml->schemaValidate($xsdPath)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 | 2 |  |             libxml_clear_errors(); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 | 2 |  |             throw XmlNotValid::new(); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 | 17 |  |         $xml    = simplexml_load_file($file, 'SimpleXMLElement', LIBXML_NOCDATA); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 | 17 |  |         $config = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 17 |  |         if (isset($xml->name)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 37 | 13 |  |             $config['name'] = (string) $xml->name; | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 17 |  |         if (isset($xml->table['name'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 41 | 13 |  |             $config['table_name'] = (string) $xml->table['name']; | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 | 17 |  |         if (isset($xml->table['column'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 | 9 |  |             $config['column_name'] = (string) $xml->table['column']; | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 | 17 |  |         if (isset($xml->table['executed_at_column'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 | 9 |  |             $config['executed_at_column_name'] = (string) $xml->table['executed_at_column']; | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 17 |  |         if (isset($xml->{'migrations-namespace'})) { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 12 |  |             $config['migrations_namespace'] = (string) $xml->{'migrations-namespace'}; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 17 |  |         if (isset($xml->{'organize-migrations'})) { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 5 |  |             $config['organize_migrations'] = (string) $xml->{'organize-migrations'}; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 17 |  |         if (isset($xml->{'migrations-directory'})) { | 
            
                                                                        
                            
            
                                    
            
            
                | 61 | 12 |  |             $config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, (string) $xml->{'migrations-directory'}); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 17 |  |         if (isset($xml->migrations->migration)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 65 | 1 |  |             $migrations = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 | 1 |  |             foreach ($xml->migrations->migration as $migration) { | 
            
                                                                        
                            
            
                                    
            
            
                | 68 | 1 |  |                 $attributes = $migration->attributes(); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 | 1 |  |                 $version = (string) $attributes['version']; | 
            
                                                                        
                            
            
                                    
            
            
                | 71 | 1 |  |                 $class   = (string) $attributes['class']; | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 1 |  |                 $migrations[] = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 74 | 1 |  |                     'version' => $version, | 
            
                                                                        
                            
            
                                    
            
            
                | 75 | 1 |  |                     'class' => $class, | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |                 ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 79 | 1 |  |             $config['migrations'] = $migrations; | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 | 17 |  |         $this->setConfiguration($config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 16 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 84 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |  |