App\Libraries\SettingDotEnv::load PHP Method

load() public static method

public static load ( $path, $file = '.env' )
    public static function load($path, $file = '.env')
    {
        $cnt = 0;
        $lines = null;
        if (!is_string($file)) {
            $file = '.env';
        }
        $filePath = rtrim($path, '/') . '/' . $file;
        if (!is_readable($filePath) || !is_file($filePath)) {
            throw new \InvalidArgumentException(sprintf('File %s not found or not readable. ' . 'Create file with your environment settings at %s', $file, $filePath));
        }
        // Read file into an array of lines with auto-detected line endings
        $autodetect = ini_get('auto_detect_line_endings');
        ini_set('auto_detect_line_endings', '1');
        $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        ini_set('auto_detect_line_endings', $autodetect);
        foreach ($lines as $line) {
            // Disregard comments
            if (strpos(trim($line), '#') === 0) {
                continue;
            }
            // Only use non-empty lines that look like setters
            if (strpos($line, '=') !== false) {
                $cnt = $cnt + static::setSettingFromEnv($line);
            }
        }
        return $cnt;
    }

Usage Example

コード例 #1
0
 public function load($envName)
 {
     $cnt = 0;
     $settingsFileName = ".settings-" . $envName;
     $settingsPath = self::$app->environmentPath();
     $settingsFullFileName = $settingsPath . '/' . $settingsFileName;
     if (\File::exists($settingsFullFileName)) {
         $cnt = SettingDotEnv::load($settingsPath, $settingsFileName);
     } else {
         throw new FileNotFoundException($settingsFullFileName);
     }
     return $cnt;
 }
All Usage Examples Of App\Libraries\SettingDotEnv::load