| @@ 8-56 (lines=49) @@ | ||
| 5 | use Dotenv\Dotenv; |
|
| 6 | use Illuminate\Support\Collection; |
|
| 7 | ||
| 8 | class ExampleEnvironmentVariablesAreSet implements Check |
|
| 9 | { |
|
| 10 | /** @var Collection */ |
|
| 11 | private $envVariables; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * The name of the check. |
|
| 15 | * |
|
| 16 | * @param array $config |
|
| 17 | * @return string |
|
| 18 | */ |
|
| 19 | public function name(array $config): string |
|
| 20 | { |
|
| 21 | return trans('self-diagnosis::checks.example_environment_variables_are_set.name'); |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * Perform the actual verification of this check. |
|
| 26 | * |
|
| 27 | * @param array $config |
|
| 28 | * @return bool |
|
| 29 | */ |
|
| 30 | public function check(array $config): bool |
|
| 31 | { |
|
| 32 | $examples = new Dotenv(base_path(), '.env.example'); |
|
| 33 | $examples->safeLoad(); |
|
| 34 | ||
| 35 | $actual = new Dotenv(base_path(), '.env'); |
|
| 36 | $actual->safeLoad(); |
|
| 37 | ||
| 38 | $this->envVariables = Collection::make($examples->getEnvironmentVariableNames()) |
|
| 39 | ->diff($actual->getEnvironmentVariableNames()); |
|
| 40 | ||
| 41 | return $this->envVariables->isEmpty(); |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * The error message to display in case the check does not pass. |
|
| 46 | * |
|
| 47 | * @param array $config |
|
| 48 | * @return string |
|
| 49 | */ |
|
| 50 | public function message(array $config): string |
|
| 51 | { |
|
| 52 | return trans('self-diagnosis::checks.example_environment_variables_are_set.message', [ |
|
| 53 | 'variables' => $this->envVariables->implode(PHP_EOL), |
|
| 54 | ]); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||
| @@ 8-56 (lines=49) @@ | ||
| 5 | use Dotenv\Dotenv; |
|
| 6 | use Illuminate\Support\Collection; |
|
| 7 | ||
| 8 | class ExampleEnvironmentVariablesAreUpToDate implements Check |
|
| 9 | { |
|
| 10 | /** @var Collection */ |
|
| 11 | private $envVariables; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * The name of the check. |
|
| 15 | * |
|
| 16 | * @param array $config |
|
| 17 | * @return string |
|
| 18 | */ |
|
| 19 | public function name(array $config): string |
|
| 20 | { |
|
| 21 | return trans('self-diagnosis::checks.example_environment_variables_are_up_to_date.name'); |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * Perform the actual verification of this check. |
|
| 26 | * |
|
| 27 | * @param array $config |
|
| 28 | * @return bool |
|
| 29 | */ |
|
| 30 | public function check(array $config): bool |
|
| 31 | { |
|
| 32 | $examples = new Dotenv(base_path(), '.env.example'); |
|
| 33 | $examples->safeLoad(); |
|
| 34 | ||
| 35 | $actual = new Dotenv(base_path(), '.env'); |
|
| 36 | $actual->safeLoad(); |
|
| 37 | ||
| 38 | $this->envVariables = Collection::make($actual->getEnvironmentVariableNames()) |
|
| 39 | ->diff($examples->getEnvironmentVariableNames()); |
|
| 40 | ||
| 41 | return $this->envVariables->isEmpty(); |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * The error message to display in case the check does not pass. |
|
| 46 | * |
|
| 47 | * @param array $config |
|
| 48 | * @return string |
|
| 49 | */ |
|
| 50 | public function message(array $config): string |
|
| 51 | { |
|
| 52 | return trans('self-diagnosis::checks.example_environment_variables_are_up_to_date.message', [ |
|
| 53 | 'variables' => $this->envVariables->implode(PHP_EOL), |
|
| 54 | ]); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||