| @@ 5-32 (lines=28) @@ | ||
| 2 | ||
| 3 | namespace Bmitch\Envsync\Finders; |
|
| 4 | ||
| 5 | class EnvFileFinder |
|
| 6 | { |
|
| 7 | ||
| 8 | /** |
|
| 9 | * Regex pattern to use to find environment variables. |
|
| 10 | * @var string $contents Regular Expression. |
|
| 11 | */ |
|
| 12 | public static $pattern = "/([A-Za-z_]{1,})=/"; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * Finds the environment variables within the $file. |
|
| 16 | * @param string $file Path and filename. |
|
| 17 | * @return array |
|
| 18 | */ |
|
| 19 | public function find($file) |
|
| 20 | { |
|
| 21 | $contents = file_get_contents($file); |
|
| 22 | ||
| 23 | $envs = []; |
|
| 24 | ||
| 25 | preg_match_all(self::$pattern, $contents, $matches); |
|
| 26 | if (isset($matches[1])) { |
|
| 27 | $envs = $matches[1]; |
|
| 28 | } |
|
| 29 | ||
| 30 | return $envs; |
|
| 31 | } |
|
| 32 | } |
|
| 33 | ||
| @@ 5-32 (lines=28) @@ | ||
| 2 | ||
| 3 | namespace Bmitch\Envsync\Finders; |
|
| 4 | ||
| 5 | class PhpFileFinder |
|
| 6 | { |
|
| 7 | ||
| 8 | /** |
|
| 9 | * Regex pattern to use to find environment variables. |
|
| 10 | * @var string $contents Regular Expression. |
|
| 11 | */ |
|
| 12 | public static $pattern = "/env\(['\"]([A-Za-z_]{1,})/"; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * Finds the environment variables within the $file. |
|
| 16 | * @param string $file Path and filename. |
|
| 17 | * @return array |
|
| 18 | */ |
|
| 19 | public function find($file) |
|
| 20 | { |
|
| 21 | $contents = file_get_contents($file); |
|
| 22 | ||
| 23 | $envs = []; |
|
| 24 | ||
| 25 | preg_match_all(self::$pattern, $contents, $matches); |
|
| 26 | if (isset($matches[1])) { |
|
| 27 | $envs = $matches[1]; |
|
| 28 | } |
|
| 29 | ||
| 30 | return $envs; |
|
| 31 | } |
|
| 32 | } |
|
| 33 | ||