Skip to content

Commit

Permalink
Update index.php
Browse files Browse the repository at this point in the history
Explanation of changes:

1. Extracted the runtime options array into a separate variable for better readability.
2. Used the runtime options array when accessing the context values, making it easier to change the options in the future.
3. Introduced a null check when accessing the environment variable to avoid warnings if it's not present in the context.
4. Used the null coalescing operator (??) to provide a default value of null for the environment variable if it's not present in the context.
5. Simplified the debug variable assignment using the ternary operator and explicit type casting to bool.
6. Added a use statement to import the $runtimeOptions variable into the anonymous function, allowing access to the options within the function.
  • Loading branch information
hedho committed May 18, 2023
1 parent 033e308 commit 7284968
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@

use SolidInvoice\Kernel;

$_SERVER['APP_RUNTIME_OPTIONS'] = [
$runtimeOptions = [
'env_var_name' => 'SOLIDINVOICE_ENV',
'debug_var_name' => 'SOLIDINVOICE_DEBUG'
];

$_SERVER['APP_RUNTIME_OPTIONS'] = $runtimeOptions;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return static function (array $context) {
return new Kernel($context['SOLIDINVOICE_ENV'], (bool) $context['SOLIDINVOICE_DEBUG']);
return static function (array $context) use ($runtimeOptions) {
$environment = $context[$runtimeOptions['env_var_name']] ?? null;
$debug = isset($context[$runtimeOptions['debug_var_name']]) ? (bool) $context[$runtimeOptions['debug_var_name']] : false;

return new Kernel($environment, $debug);
};

0 comments on commit 7284968

Please sign in to comment.