Skip to content
Permalink
Browse files

Using autoloader

  • Loading branch information...
Thoulah committed Mar 16, 2019
1 parent cf0e8c5 commit 00db33a479e2c43e44827ba50abc80eb96744185
Showing with 350 additions and 115 deletions.
  1. +1 −1 .gitignore
  2. +42 −0 App.php
  3. +8 −1 composer.json
  4. +255 −14 composer.lock
  5. +16 −0 mister42/Params.php
  6. +7 −9 mister42/common.php
  7. +0 −12 mister42/params.php
  8. +2 −13 mister42/tests/_bootstrap.php
  9. +14 −15 mister42/web.php
  10. +2 −2 mr42/web.php
  11. +1 −33 webroot/index.php
  12. +2 −15 yii
@@ -1,3 +1,3 @@
/mister42/secrets.php
/mister42/Secrets.php
/webroot/.htaccess
/webroot/php.ini
42 App.php
@@ -0,0 +1,42 @@
<?php
class App {
public function __construct(bool $debug = false, bool $unitTest = false) {
if ($debug) :
error_reporting(-1);
define('YII_DEBUG', true);
endif;
header_remove("X-Powered-By");
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../vendor/yiisoft/yii2/Yii.php';
if ($unitTest) :
define('YII_ENABLE_ERROR_HANDLER', false);
return new yii\web\Application($this->loadConfig(['mister42'], 'web'));
endif;
$app = (php_sapi_name() === 'cli')
? new yii\console\Application($this->loadConfig(['mister42'], 'console'))
: new yii\web\Application($this->getConfig());
$exitCode = $app->run();
exit($exitCode);
}
private function getConfig(): array {
switch (yii\helpers\ArrayHelper::getValue($_SERVER, 'SERVER_NAME')) :
case 'mister42.me':
return $this->loadConfig(['mister42'], 'web');
default:
return $this->loadConfig(['mister42', 'mr42'], 'web');
endswitch;
}
private function loadConfig(array $dir, string $confFile): array {
$webConfig = $dir[1] ?? $dir[0];
return yii\helpers\ArrayHelper::merge(
require __DIR__."/{$dir[0]}/common.php",
require __DIR__."/{$webConfig}/{$confFile}.php"
);
}
}
@@ -5,9 +5,16 @@
"license": "GPL-3.0-only",
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-0": { "": "mister42/" },
"psr-4": {"app\\": "mister42/"}
},
"config": {
"component-dir": "../vendor-components",
"vendor-dir": "../vendor"
"vendor-dir": "../vendor",
"platform": {
"php": "7.3.3"
}
},
"require": {
"php": ">=7.1.0",

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 00db33a

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.