Removed reliance on global from Dispatcher

This commit is contained in:
Marcin Kurczewski 2014-10-04 13:34:08 +02:00
parent 4220a83589
commit a728279bf5
3 changed files with 13 additions and 7 deletions

View file

@ -1,9 +1,6 @@
<?php
$start = microtime(true);
require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Bootstrap.php');
\Szurubooru\Bootstrap::init();
$httpHelper = \Szurubooru\Injector::get(\Szurubooru\Helpers\HttpHelper::class);
$dispatcher = \Szurubooru\Injector::get(\Szurubooru\Dispatcher::class);
$dispatcher->run($httpHelper->getRequestMethod(), $_GET['q']);

View file

@ -1,14 +1,24 @@
<?php
namespace Szurubooru;
$startTime = microtime(true);
final class Bootstrap
{
public static function init()
private static $startTime;
public static function init($startTime)
{
self::$startTime = $startTime;
self::turnErrorsIntoExceptions();
self::initAutoloader();
}
public static function getStartTime()
{
return self::$startTime;
}
private static function initAutoloader()
{
require(__DIR__
@ -27,4 +37,4 @@ final class Bootstrap
}
}
Bootstrap::init();
Bootstrap::init($startTime);

View file

@ -31,7 +31,6 @@ final class Dispatcher
public function run($requestMethod, $requestUri)
{
global $start;
try
{
$code = 200;
@ -50,7 +49,7 @@ final class Dispatcher
];
}
$end = microtime(true);
$json['__time'] = $end - $start;
$json['__time'] = $end - \Szurubooru\Bootstrap::getStartTime();
$json['__queries'] = $this->databaseConnection->getPDO()->getQueryCount();
$this->httpHelper->setResponseCode($code);