Skip to content

Instantly share code, notes, and snippets.

@rmrhz
Created December 28, 2017 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmrhz/8eaf27e290a8b9f4241f66ddfea7cca6 to your computer and use it in GitHub Desktop.
Save rmrhz/8eaf27e290a8b9f4241f66ddfea7cca6 to your computer and use it in GitHub Desktop.
{
"require": {
"vlucas/phpdotenv": "^2.5@dev",
"jeremykendall/php-domain-parser": "~2.0"
}
}
<?php
require_once dirname(dirname(__FILE__)) . '/init.php';
// Base configuration
define('YII_DEBUG', env('YII_APP_DEBUG', true));
define('YII_ENV', env('YII_APP_ENV', 'production'));
$domain = new Pdp\Parser( (new Pdp\PublicSuffixListManager)->getList() );
$subdomain = $domain->parseUrl($_SERVER['HTTP_HOST'])->toArray()['subdomain'];
switch($subdomain)
{
default:
case null:
$config = getConfig('index');
break;
case env('YII_APP_SUBDOMAIN', 'app'):
$config = getConfig('app');
break;
case env('YII_ADMIN_SUBDOMAIN', 'admin'):
$config = getConfig('admin');
break;
}
$application = new yii\web\Application($config);
$application->run();
<?php
require_once "vendor/autoload.php";
// Load environment variable
$env = new Dotenv\Dotenv(dirname(__FILE__));
$env->load();
/**
* Returns the base path
*
* @param string $filename
* @return string
*/
function basePath($filename = null)
{
$path = dirname(__FILE__);
return is_null($filename) ? $path : $path . '/' . $filename;
}
/**
* Gets the value from the environment file
*
* @param string $key
* @param mixed $val Default value
*/
function env(string $key, $val = null)
{
return ! is_null($return = getenv($key)) ? $return : $val;
}
/**
* Gets the correct config for the environment
*
* @param string $envrionment
* @return array
*/
function getConfig(string $environment) : array
{
$config = [];
$merge_config = [];
$config = require_once(basePath('config/yii2/' . $environment . '/main.php'));
foreach(glob(basePath('config/yii2/*.php')) as $file) {
$merge_config[basename($file, ".php")] = require_once $file;
}
return array_merge_recursive($config, $merge_config);
}
$aliases = [
// aliases here
];
array_walk_recursive($aliases, function($val, $key) {
Yii::setAlias($key, $val);
});
#!/usr/bin/env php
<?php
require_once 'init.php';
@define('YII_DEBUG', env('YII_APP_DEBUG', true));
@define('YII_ENV', env('YII_APP_ENV', 'production'));
$config = getConfig('console');
/**
* Configurations which are not needed
*
*/
unset($config['components']['request']);
unset($config['components']['errorHandler']);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment