| 1 | efrain | 1 | <?php
 | 
        
           |  |  | 2 | namespace Aws\Token;
 | 
        
           |  |  | 3 |   | 
        
           |  |  | 4 | trait ParsesIniTrait
 | 
        
           |  |  | 5 | {
 | 
        
           |  |  | 6 |     /**
 | 
        
           |  |  | 7 |      * Gets profiles from specified $filename, or default ini files.
 | 
        
           |  |  | 8 |      */
 | 
        
           |  |  | 9 |     private static function loadProfiles($filename)
 | 
        
           |  |  | 10 |     {
 | 
        
           |  |  | 11 |         $profileData = \Aws\parse_ini_file($filename, true, INI_SCANNER_RAW);
 | 
        
           |  |  | 12 |         $configFilename = self::getHomeDir() . '/.aws/config';
 | 
        
           |  |  | 13 |         if (is_readable($configFilename)) {
 | 
        
           |  |  | 14 |             $configProfiles = \Aws\parse_ini_file($configFilename, true, INI_SCANNER_RAW);
 | 
        
           |  |  | 15 |             $profileData = array_merge($configProfiles, $profileData);
 | 
        
           |  |  | 16 |         }
 | 
        
           |  |  | 17 |         foreach ($profileData as $name => $profile) {
 | 
        
           |  |  | 18 |             // standardize config profile names
 | 
        
           |  |  | 19 |             $name = str_replace('profile ', '', $name);
 | 
        
           |  |  | 20 |             $profileData[$name] = $profile;
 | 
        
           |  |  | 21 |         }
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 |         return $profileData;
 | 
        
           |  |  | 24 |     }
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 |     /**
 | 
        
           |  |  | 27 |      * Gets the environment's HOME directory if available.
 | 
        
           |  |  | 28 |      *
 | 
        
           |  |  | 29 |      * @return null|string
 | 
        
           |  |  | 30 |      */
 | 
        
           |  |  | 31 |     private static function getHomeDir()
 | 
        
           |  |  | 32 |     {
 | 
        
           |  |  | 33 |         // On Linux/Unix-like systems, use the HOME environment variable
 | 
        
           |  |  | 34 |         if ($homeDir = getenv('HOME')) {
 | 
        
           |  |  | 35 |             return $homeDir;
 | 
        
           |  |  | 36 |         }
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 |         // Get the HOMEDRIVE and HOMEPATH values for Windows hosts
 | 
        
           |  |  | 39 |         $homeDrive = getenv('HOMEDRIVE');
 | 
        
           |  |  | 40 |         $homePath = getenv('HOMEPATH');
 | 
        
           |  |  | 41 |   | 
        
           |  |  | 42 |         return ($homeDrive && $homePath) ? $homeDrive . $homePath : null;
 | 
        
           |  |  | 43 |     }
 | 
        
           |  |  | 44 | }
 |