| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright © Vaimo Group. All rights reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * See LICENSE_VAIMO.txt for license details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | namespace Vaimo\ComposerPatches\Patcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Composer\Package\PackageInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Vaimo\ComposerPatches\Config as Keys; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class ConfigReader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @var \Vaimo\ComposerPatches\Interfaces\PackageConfigExtractorInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     private $infoExtractor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @param \Vaimo\ComposerPatches\Interfaces\PackageConfigExtractorInterface $infoExtractor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         \Vaimo\ComposerPatches\Interfaces\PackageConfigExtractorInterface $infoExtractor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->infoExtractor = $infoExtractor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     public function readFromPackage(PackageInterface $package) | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $config = array_filter( | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             (array)$this->infoExtractor->getConfig($package, Keys::CONFIG_ROOT) | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         return $this->mirrorConfigValues($config, array( | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             Keys::PATCHER_FILE_DEV => Keys::DEV_DEFINITIONS_FILE, | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             Keys::PATCHER_FILE => Keys::DEFINITIONS_FILE, | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             Keys::PATCHER_SEARCH => Keys::DEFINITIONS_SEARCH, | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |             Keys::PATCHER_SEARCH_DEV => Keys::DEV_DEFINITIONS_SEARCH, | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |             Keys::PATCHER_TARGETS => Keys::PATCHES_DEPENDS, | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |             Keys::PATCHER_BASE_PATHS => Keys::PATCHES_BASE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     private function mirrorConfigValues(array $config, array $keyMap) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         if (isset($config[Keys::PATCHER_CONFIG_ROOT])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $patcherConfig = (array)$config[Keys::PATCHER_CONFIG_ROOT]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             foreach ($keyMap as $source => $target) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 if (!isset($config[$target]) && isset($patcherConfig[$source])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     $config[$target] = $patcherConfig[$source]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |  |