Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Application {
- /** @var Database_Adapter **/
- public $db = NULL;
- /** @var Cache **/
- public static $cache = NULL;
- /** @var Request **/
- public $request = NULL;
- /** @var array **/
- public $params = array();
- public $begin_mem, $begin_time, $end_mem, $end_time;
- /**
- * @return Cache
- **/
- public static function cache()
- {
- return self::$cache;
- }
- /**
- * Initier l'application.
- * @throws Exception
- * @param array $conf
- * @return bool
- */
- public function init()
- {
- global $application;
- $config = new Config();
- $application->begin_time = $application->microtime_float();
- $application->begin_mem = memory_get_usage();
- $this->ConnectDatabase();
- self::$cache = new Cache;
- self::$cache->init();
- // User::init();
- // set_exception_handler(array('Error', 'handle'));
- //self::$request = Request::instance();
- return TRUE;
- }
- private function ConnectDatabase(){
- global $database;
- $database->getPDO();
- }
- /** @return null **/
- public function run()
- {
- global $application;
- Router::init();
- //self::$request->init();
- ob_start();
- Router::dispatch();
- $content = ob_get_clean();
- $application->end_time = $application->microtime_float();
- $application->end_mem = memory_get_usage();
- include_once ROOT.'layouts/ocean.php';
- }
- protected function convert($size)
- {
- $unit=array('B','Kb','Mb','Gb','Tb','Pb');
- return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
- }
- /** @return string **/
- function microtime_float() {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
- public function stats()
- {
- global $application;
- $time = round($application->end_time - $application->begin_time, 4);
- $mem = $application->convert($application->end_mem);
- return "Page généré en $time s, $mem de mémoire utilisé.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement