| @@ 64-81 (lines=18) @@ | ||
| 61 | * |
|
| 62 | * @return \Phinx\Config\Config |
|
| 63 | */ |
|
| 64 | public static function fromYaml($configFilePath) |
|
| 65 | { |
|
| 66 | if (!class_exists('Symfony\\Component\\Yaml\\Yaml', true)) { |
|
| 67 | throw new RuntimeException('Missing yaml parser, symfony/yaml package is not installed.'); |
|
| 68 | } |
|
| 69 | ||
| 70 | $configFile = file_get_contents($configFilePath); |
|
| 71 | $configArray = Yaml::parse($configFile); |
|
| 72 | ||
| 73 | if (!is_array($configArray)) { |
|
| 74 | throw new RuntimeException(sprintf( |
|
| 75 | 'File \'%s\' must be valid YAML', |
|
| 76 | $configFilePath |
|
| 77 | )); |
|
| 78 | } |
|
| 79 | ||
| 80 | return new static($configArray, $configFilePath); |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Create a new instance of the config class using a JSON file path. |
|
| @@ 92-107 (lines=16) @@ | ||
| 89 | * |
|
| 90 | * @return \Phinx\Config\Config |
|
| 91 | */ |
|
| 92 | public static function fromJson($configFilePath) |
|
| 93 | { |
|
| 94 | if (!function_exists('json_decode')) { |
|
| 95 | throw new RuntimeException("Need to install JSON PHP extension to use JSON config"); |
|
| 96 | } |
|
| 97 | ||
| 98 | $configArray = json_decode(file_get_contents($configFilePath), true); |
|
| 99 | if (!is_array($configArray)) { |
|
| 100 | throw new RuntimeException(sprintf( |
|
| 101 | 'File \'%s\' must be valid JSON', |
|
| 102 | $configFilePath |
|
| 103 | )); |
|
| 104 | } |
|
| 105 | ||
| 106 | return new static($configArray, $configFilePath); |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Create a new instance of the config class using a PHP file path. |
|