| @@ 8-64 (lines=57) @@ | ||
| 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 | * Construct the check, pre set the private variable. |
|
| 15 | */ |
|
| 16 | public function __construct() |
|
| 17 | { |
|
| 18 | $this->envVariables = new Collection(); |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * The name of the check. |
|
| 23 | * |
|
| 24 | * @param array $config |
|
| 25 | * @return string |
|
| 26 | */ |
|
| 27 | public function name(array $config): string |
|
| 28 | { |
|
| 29 | return trans('self-diagnosis::checks.example_environment_variables_are_set.name'); |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Perform the actual verification of this check. |
|
| 34 | * |
|
| 35 | * @param array $config |
|
| 36 | * @return bool |
|
| 37 | */ |
|
| 38 | public function check(array $config): bool |
|
| 39 | { |
|
| 40 | $examples = new Dotenv(base_path(), '.env.example'); |
|
| 41 | $examples->safeLoad(); |
|
| 42 | ||
| 43 | $actual = new Dotenv(base_path(), '.env'); |
|
| 44 | $actual->safeLoad(); |
|
| 45 | ||
| 46 | $this->envVariables = Collection::make($examples->getEnvironmentVariableNames()) |
|
| 47 | ->diff($actual->getEnvironmentVariableNames()); |
|
| 48 | ||
| 49 | return $this->envVariables->isEmpty(); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * The error message to display in case the check does not pass. |
|
| 54 | * |
|
| 55 | * @param array $config |
|
| 56 | * @return string |
|
| 57 | */ |
|
| 58 | public function message(array $config): string |
|
| 59 | { |
|
| 60 | return trans('self-diagnosis::checks.example_environment_variables_are_set.message', [ |
|
| 61 | 'variables' => $this->envVariables->implode(PHP_EOL), |
|
| 62 | ]); |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||
| @@ 8-64 (lines=57) @@ | ||
| 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 | * Construct the check, pre set the private variable. |
|
| 15 | */ |
|
| 16 | public function __construct() |
|
| 17 | { |
|
| 18 | $this->envVariables = new Collection(); |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * The name of the check. |
|
| 23 | * |
|
| 24 | * @param array $config |
|
| 25 | * @return string |
|
| 26 | */ |
|
| 27 | public function name(array $config): string |
|
| 28 | { |
|
| 29 | return trans('self-diagnosis::checks.example_environment_variables_are_up_to_date.name'); |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Perform the actual verification of this check. |
|
| 34 | * |
|
| 35 | * @param array $config |
|
| 36 | * @return bool |
|
| 37 | */ |
|
| 38 | public function check(array $config): bool |
|
| 39 | { |
|
| 40 | $examples = new Dotenv(base_path(), '.env.example'); |
|
| 41 | $examples->safeLoad(); |
|
| 42 | ||
| 43 | $actual = new Dotenv(base_path(), '.env'); |
|
| 44 | $actual->safeLoad(); |
|
| 45 | ||
| 46 | $this->envVariables = Collection::make($actual->getEnvironmentVariableNames()) |
|
| 47 | ->diff($examples->getEnvironmentVariableNames()); |
|
| 48 | ||
| 49 | return $this->envVariables->isEmpty(); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * The error message to display in case the check does not pass. |
|
| 54 | * |
|
| 55 | * @param array $config |
|
| 56 | * @return string |
|
| 57 | */ |
|
| 58 | public function message(array $config): string |
|
| 59 | { |
|
| 60 | return trans('self-diagnosis::checks.example_environment_variables_are_up_to_date.message', [ |
|
| 61 | 'variables' => $this->envVariables->implode(PHP_EOL), |
|
| 62 | ]); |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||