/** * Initializes the application environment. * * @param string $configPath absolute path to the application's main configuration file * @param string $env the configuration environment to use * @param string $callback an optional callback function to execute uplon completion * @param boolean $session whether or not to start a session */ public static function init($configPath = '', $env = 'main', $callback = '', $session = true) { // Load Configuration require_once 'Common/Config.php'; require_once 'Common/Config/Xml.php'; if(!is_file($configPath)) { header('Location: install/'); } $config = new \Bedrock\Common\Config\Xml($configPath, $env); // Setup define('ROOT', $config->root->system); switch($config->env->os) { default: case 'unix': define('DELIMITER', self::DELIM_UNIX); break; case 'windows': define('DELIMITER', self::DELIM_WIN); break; } // Autoload Function spl_autoload_register(function($className) { // Imports require_once ROOT . '/lib/Bedrock.php'; require_once ROOT . '/lib/Bedrock/Common.php'; \Bedrock\Common::autoload($className, ROOT); }); // Register Configuration \Bedrock\Common\Registry::set('config', $config); // Include Paths ini_set('include_path', ini_get('include_path') . DELIMITER . ROOT . DELIMITER . $config->root->cfg . DELIMITER . $config->root->lib . DELIMITER . $config->root->pub); // Error Reporting/Handling eval('error_reporting(' . $config->env->error . ');'); set_error_handler('\\Bedrock\\Common::error', E_ALL - E_NOTICE); // Initialize: Logger \Bedrock\Common\Logger::init(\Bedrock\Common\Logger::LEVEL_INFO, $config->meta->title, $config->meta->version->application, $config->meta->status); // Add built-in targets that are enabled... if($config->logger->targets->system->active) { \Bedrock\Common\Logger::addTarget(new \Bedrock\Common\Logger\Target\System(), $config->logger->targets->system->level); } if($config->logger->targets->file->active) { \Bedrock\Common\Logger::addTarget(new \Bedrock\Common\Logger\Target\File($config->root->log . DIRECTORY_SEPARATOR . date('Y-m-d') . '.log'), $config->logger->targets->file->level); } if($config->logger->targets->firephp->active) { \Bedrock\Common\Logger::addTarget(new \Bedrock\Common\Logger\Target\FirePHP(), $config->logger->targets->firephp->level); } if($config->logger->targets->growl->active) { \Bedrock\Common\Logger::addTarget(new \Bedrock\Common\Logger\Target\Growl(array($config->growl->host, $config->growl->password, $config->meta->title)), $config->logger->targets->growl->level); } // Initialize: Session if($session) { \Bedrock\Common\Session::start(); } $router = new \Bedrock\Common\Router(); \Bedrock\Common\Registry::set('router', $router); // Execute Callback if($callback) { call_user_func($callback); } }