/** * Reads token from session * * @return string */ public function getToken() { if ($this->_session->get(self::$_tokenname) !== null) { return $this->_session->get(self::$_tokenname); } else { return false; } }
/** * Main framework initialization method * * @return type * @throws Exception */ public static function initialize() { if (!defined('APP_PATH')) { throw new Exception('APP_PATH not defined'); } // fix extra backslashes in $_POST/$_GET if (get_magic_quotes_gpc()) { $globals = array('_POST', '_GET', '_COOKIE', '_REQUEST', '_SESSION'); foreach ($globals as $global) { if (isset($GLOBALS[$global])) { $GLOBALS[$global] = self::_clean($GLOBALS[$global]); } } } // Autoloader $prefixes = array(APP_PATH . DIRECTORY_SEPARATOR . 'vendors', APP_PATH . DIRECTORY_SEPARATOR . 'application', APP_PATH . DIRECTORY_SEPARATOR . 'modules', APP_PATH . DIRECTORY_SEPARATOR . 'public'); require_once APP_PATH . '/vendors/thcframe/core/autoloader.php'; self::$_autoloader = new Autoloader(); self::$_autoloader->addPrefixes($prefixes); self::$_autoloader->register(); // Logger $logger = new Logger(); self::$_logger = $logger->initialize(); // error and exception handlers set_error_handler(__CLASS__ . '::_errorHandler'); set_exception_handler(__CLASS__ . '::_exceptionHandler'); try { // configuration $configuration = new \THCFrame\Configuration\Configuration(array('type' => 'ini', 'options' => array('env' => ENV))); $confingInitialized = $configuration->initialize(); Registry::set('config', $confingInitialized); $parsedConfig = $confingInitialized->getParsed(); // database if ($parsedConfig->database->host != '') { $database = new \THCFrame\Database\Database(); $initializedDb = $database->initialize($parsedConfig); Registry::set('database', $initializedDb); $initializedDb->connect(); //extend configuration for config loaded from db $confingInitialized->extendForDbConfig(); } // cache $cache = new \THCFrame\Cache\Cache(); Registry::set('cache', $cache->initialize($parsedConfig)); // session $session = new \THCFrame\Session\Session(); Registry::set('session', $session->initialize($parsedConfig)); // security $security = new \THCFrame\Security\Security(); Registry::set('security', $security->initialize($parsedConfig)); // unset globals unset($configuration); unset($parsedConfig); unset($database); unset($cache); unset($session); unset($security); } catch (\Exception $e) { $exception = get_class($e); // attempt to find the approapriate error template, and render foreach (self::$_exceptions as $template => $classes) { foreach ($classes as $class) { if ($class == $exception) { $defaultErrorFile = MODULES_PATH . "/app/view/errors/{$template}.phtml"; http_response_code($template); header('Content-type: text/html'); include $defaultErrorFile; exit; } } } // render fallback template http_response_code(500); header('Content-type: text/html'); echo 'An error occurred.'; if (ENV == 'dev') { print_r($e); } exit; } }