Skip to content

Commit

Permalink
Updated config and index to allow changes based on environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Parker committed Oct 7, 2016
1 parent 7e14e74 commit 29b7d4b
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 90 deletions.
137 changes: 136 additions & 1 deletion config.sample.php
Expand Up @@ -14,14 +14,149 @@
$system['release'] = '{release}';
$system['installed'] = '{datenow}';

/**
* If set to PROD, errors will be generated in the logs
* directory (app/tmp/logs/*.txt). If set to DEV, then
* errors will be displayed on the screen. For security
* reasons, when made live to the world, this should be
* set to PROD.
*/
defined('APP_ENV') or define('APP_ENV', 'PROD');

/**
* Application path.
*/
defined('APP_PATH') or define('APP_PATH', BASE_PATH . 'app' . DS);

/**
* Dropins Path.
*/
defined('ETSIS_DROPIN_DIR') or define('ETSIS_DROPIN_DIR', APP_PATH . 'dropins' . DS);

/**
* Plugins path.
*/
defined('ETSIS_PLUGIN_DIR') or define('ETSIS_PLUGIN_DIR', APP_PATH . 'plugins' . DS);

/**
* Old Dropins path for backwards compatibility.
*/
defined('DROPINS_DIR') or define('DROPINS_DIR', ETSIS_DROPIN_DIR);

/**
* Old Plugins path for backwards compatibility.
*/
defined('PLUGINS_DIR') or define('PLUGINS_DIR', ETSIS_PLUGIN_DIR);

/**
* Cache path.
*/
defined('CACHE_PATH') or define('CACHE_PATH', APP_PATH . 'tmp' . DS . 'cache' . DS);

/**
* Image path for .pdf's.
*/
defined('K_PATH_IMAGES') or define('K_PATH_IMAGES', BASE_PATH . 'static' . DS . 'images' . DS);

/**
* Set for low ram cache.
*/
defined('ETSIS_FILE_CACHE_LOW_RAM') or define('ETSIS_FILE_CACHE_LOW_RAM', '');

/**
* Instantiate a Liten application
*
* You can update
*/
$subdomain = '';
$domain_parts = explode('.', $_SERVER['SERVER_NAME']);
if (count($domain_parts) == 3) {
$subdomain = $domain_parts[0];
} else {
$subdomain = 'www';
}
$app = new \Liten\Liten(
[
'cookies.lifetime' => '86400',
'cookies.savepath' => ini_get('session.save_path') . DS . $subdomain . DS,
'file.savepath' => ini_get('session.save_path') . DS . $subdomain . DS . 'files' . DS
]
);

/**
* Database details
*/
defined('DB_HOST') or define('DB_HOST', '{hostname}');
defined('DB_NAME') or define('DB_NAME', '{database}');
defined('DB_USER') or define('DB_USER', '{username}');
defined('DB_PASS') or define('DB_PASS', '{password}');

/**
* NodeQ noSQL details.
*/
defined('NODEQ_PATH') or define('NODEQ_PATH', $app->config('cookies.savepath') . 'nodes' . DS);

/**
* Do not edit anything from this point on.
*/

$app->inst->singleton('db', function () {
$pdo = new \PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS, [\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"]);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pdo->query('SET CHARACTER SET utf8');
return new \Liten\Orm($pdo);
});
});

/**
* Require a functions file
*
* A functions file may include any dependency injections
* or preliminary functions for your application.
*/
require( APP_PATH . 'functions.php' );
require( APP_PATH . 'functions' . DS . 'dependency.php' );
if (file_exists(BASE_PATH . 'config.php')) {
require( APP_PATH . 'functions' . DS . 'hook-function.php' );
}
require( APP_PATH . 'application.php' );

/**
* Include the routers needed
*
* Lazy load the routers. A router is loaded
* only when it is needed.
*/
include(APP_PATH . 'routers.php');

benchmark_init();
if (file_exists(BASE_PATH . 'config.php')) {
date_default_timezone_set((get_option('system_timezone') !== NULL) ? get_option('system_timezone') : 'America/New_York');
} else {
date_default_timezone_set('America/New_York');
}

/**
* Autoload Dropins
*
* Dropins can be plugins and / or routers that
* should be autoloaded. This is useful when you want to
* add your own customized screens without needing to touch
* the core.
*/
if (file_exists(BASE_PATH . 'config.php')) {
$dropins = glob(APP_PATH . 'dropins' . DS . '*.php');
if (is_array($dropins)) {
foreach ($dropins as $dropin) {
if (file_exists($dropin))
include($dropin);
}
}
}

/**
* Run the Liten application
*
* This method should be called last. This executes the Liten application
* and returns the HTTP response to the HTTP client.
*/
$app->run();
91 changes: 2 additions & 89 deletions index.php
Expand Up @@ -6,109 +6,22 @@
* with the autoloader and the loading of other
* needed functions and files.
*/
defined('APP_ENV') or define('APP_ENV', 'PROD');
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
defined('BASE_PATH') or define('BASE_PATH', __DIR__ . DS);
defined('APP_PATH') or define('APP_PATH', BASE_PATH . 'app' . DS);
defined('ETSIS_DROPIN_DIR') or define('ETSIS_DROPIN_DIR', BASE_PATH . 'app' . DS . 'dropins' . DS);
defined('ETSIS_PLUGIN_DIR') or define('ETSIS_PLUGIN_DIR', BASE_PATH . 'app' . DS . 'plugins' . DS);
defined('DROPINS_DIR') or define('DROPINS_DIR', ETSIS_DROPIN_DIR);
defined('PLUGINS_DIR') or define('PLUGINS_DIR', ETSIS_PLUGIN_DIR);
defined('CACHE_PATH') or define('CACHE_PATH', APP_PATH . 'tmp' . DS . 'cache' . DS);
defined('K_PATH_IMAGES') or define('K_PATH_IMAGES', BASE_PATH . 'static' . DS . 'images' . DS);

/**
* Step 1: Require the Bootstrap
* Step 2: Require the Bootstrap
*
* The bootstrap includes defines as well as autoloader
* in order to have a working install of Liten.
*/
require( BASE_PATH . 'Liten' . DS . 'Bootstrap.php');

/**
* Step 2: Instantiate a Liten application
*
* This example instantiates a Liten application using
* its default settings. However, you can configure
* your Liten application by passing an associative array
* of setting names and values into the application constructor.
*/
$subdomain = '';
$domain_parts = explode('.', $_SERVER['SERVER_NAME']);
if (count($domain_parts) == 3) {
$subdomain = $domain_parts[0];
} else {
$subdomain = 'www';
}
$app = new \Liten\Liten(
[
'cookies.lifetime' => '86400',
'cookies.savepath' => ini_get('session.save_path') . DS . $subdomain . DS,
'file.savepath' => ini_get('session.save_path') . DS . $subdomain . DS . 'files' . DS
]
);

/**
* Step 3: Include database config file
*
* This is an example of loaded a database config
* file when calling an application that needs
* database connection.
*/
if (file_exists(BASE_PATH . 'config.php')) {
include( BASE_PATH . 'config.php' );
}

/**
* Step 4: Require a functions file
*
* A functions file may include any dependency injections
* or preliminary functions for your application.
*/
require( APP_PATH . 'functions.php' );
require( APP_PATH . 'functions' . DS . 'dependency.php' );
if (file_exists(BASE_PATH . 'config.php')) {
require( APP_PATH . 'functions' . DS . 'hook-function.php' );
}
require( APP_PATH . 'application.php' );

/**
* Step 5: Include the routers needed
*
* Lazy load the routers. A router is loaded
* only when it is needed.
*/
include(APP_PATH . 'routers.php');

benchmark_init();
if (file_exists(BASE_PATH . 'config.php')) {
date_default_timezone_set((get_option('system_timezone') !== NULL) ? get_option('system_timezone') : 'America/New_York');
} else {
date_default_timezone_set('America/New_York');
}

/**
* Step 6: Autoload Dropins
*
* Dropins can be plugins and / or routers that
* should be autoloaded. This is useful when you want to
* add your own customized screens without needing to touch
* the core.
*/
if (file_exists(BASE_PATH . 'config.php')) {
$dropins = glob(APP_PATH . 'dropins' . DS . '*.php');
if (is_array($dropins)) {
foreach ($dropins as $dropin) {
if (file_exists($dropin))
include($dropin);
}
}
}

/**
* Step 7: Run the Liten application
*
* This method should be called last. This executes the Liten application
* and returns the HTTP response to the HTTP client.
*/
$app->run();
include( BASE_PATH . 'config.php' );

0 comments on commit 29b7d4b

Please sign in to comment.