Created
August 11, 2012 05:54
-
-
Save toopay/3321594 to your computer and use it in GitHub Desktop.
Launcher Juriya
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (version_compare(PHP_VERSION, '5.3') < 0) die('Require PHP 5.'); | |
/** | |
*--------------------------------------------------------------- | |
* Set framework paths and main constants. | |
*--------------------------------------------------------------- | |
*/ | |
// Define application environment | |
define('ENVIRONMENT', $environment); | |
// Define frameworks paths | |
define('PATH_IDX', realpath(__DIR__) . DIRECTORY_SEPARATOR); | |
define('PATH_APP', realpath($application) . DIRECTORY_SEPARATOR); | |
define('PATH_MOD', realpath($modules) . DIRECTORY_SEPARATOR); | |
define('PATH_SYS', realpath($system) . DIRECTORY_SEPARATOR); | |
// Define frameworks namespaces | |
define('NS_APP', 'App\\'); | |
define('NS_MOD', 'Mod\\'); | |
define('NS_SYS', 'Juriya\\'); | |
// Define PHP extension | |
define('EXT', '.php'); | |
// Unset global variable | |
unset($environment, $application, $modules, $system); | |
/** | |
*--------------------------------------------------------------- | |
* Error reporting and display levels. | |
*--------------------------------------------------------------- | |
*/ | |
// Adjust the error reporting and display levels for each environment. | |
if (ENVIRONMENT == 'development') { | |
error_reporting(E_ALL | E_STRICT); | |
} else { | |
error_reporting(0); | |
} | |
// Turn off any errors reports. | |
ini_set('display_errors', 'Off'); | |
/** | |
*--------------------------------------------------------------- | |
* Load main framework handler. | |
*--------------------------------------------------------------- | |
*/ | |
// Load main core component | |
require_once PATH_SYS . 'Juriya' . EXT; | |
/** | |
*--------------------------------------------------------------- | |
* Set framework environment and appropriate handler. | |
*--------------------------------------------------------------- | |
*/ | |
// Limit maximum execution time | |
set_time_limit(300); | |
// Register core autoloader | |
spl_autoload_register('\\Juriya\\Juriya::autoload'); | |
// Register exception and error handler | |
set_exception_handler(function($e) { | |
Juriya\Exception::make($e)->handleException(); | |
}); | |
set_error_handler(function($errno, $errstr, $errfile, $errline) { | |
$e = array($errno, $errstr, $errfile, $errline); | |
Juriya\Exception::make($e)->handleError(); | |
}); | |
// Register shutdown handler | |
register_shutdown_function(function() { | |
// Find some premature script error | |
$lasterror = error_get_last(); | |
if ( ! empty($lasterror)) { | |
Juriya\Exception::make(array_values($lasterror))->handleError(); | |
} | |
// Generate log reports | |
Juriya\Logger::report(); | |
}); | |
/** | |
*--------------------------------------------------------------- | |
* Define framework low-level functions. | |
*--------------------------------------------------------------- | |
*/ | |
// Debugger method | |
function debug() { | |
$vars = func_get_args(); | |
echo call_user_func_array(array('\\Juriya\\Debugger', 'dump'), $vars); | |
} | |
// Logger methods | |
function log_start() { | |
if (func_num_args() === 1) { | |
$class = func_get_args(); | |
return call_user_func_array(array('\\Juriya\\Logger', 'start'), $class); | |
} | |
throw new InvalidArgumentException('Cannot start log process for undefined class'); | |
} | |
function log_stop() { | |
if (func_num_args() === 1) { | |
$class = func_get_args(); | |
return call_user_func_array(array('\\Juriya\\Logger', 'stop'), $class); | |
} | |
throw new InvalidArgumentException('Cannot stop log process for undefined class'); | |
} | |
function log_write() { | |
if (func_num_args() >= 2) { | |
$log = func_get_args(); | |
return call_user_func_array(array('\\Juriya\\Logger', 'write'), $log); | |
} | |
throw new InvalidArgumentException('Cannot write log process for undefined class'); | |
} | |
/** | |
*--------------------------------------------------------------- | |
* Load bootstrap, configuration and instantiate new launcher. | |
*--------------------------------------------------------------- | |
*/ | |
// Bootstrap pool | |
$bootstrap = array();//include_once(PATH_APP . 'bootstrap' . EXT); | |
// Config pool | |
$configs = array(); | |
// Set config path and scan the directory | |
$config = PATH_IDX; | |
is_dir($config) and $files = scandir($config); | |
if (isset($files) && ! is_null($files)) { | |
// Walk through files and extract config if exists | |
array_walk($files, function(&$file, $i, $config) use(&$files) { | |
if (substr($file, -3, 3) == 'ini') { | |
$file = parse_ini_file($config . $file, TRUE); | |
} else { | |
unset($files[$i]); | |
} | |
}, $config); | |
// Assign config collection into config pool | |
$configs = $files; | |
} | |
// Reset all vars | |
unset($path, $config, $files); | |
// Prepare Juriya Configuration | |
$config = new Juriya\Collection(); | |
$config->set('configuration', $configs); | |
// Instantiate new launcher | |
$launcher = new Juriya\Juriya($bootstrap, $config); | |
// Reset bootstrap and configs value | |
unset($bootstrap, $config, $configs); | |
/** | |
*--------------------------------------------------------------- | |
* Launch program. | |
*--------------------------------------------------------------- | |
*/ | |
// Execute the application | |
if (ENVIRONMENT != 'test') { | |
$launcher->execute(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment