Moved autoloader to composer config
This commit is contained in:
parent
7cb2588eca
commit
216d9b3001
7 changed files with 43 additions and 49 deletions
|
@ -7,5 +7,12 @@
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"jbrooksuk/phpcheckstyle": "dev-master",
|
"jbrooksuk/phpcheckstyle": "dev-master",
|
||||||
"phpunit/phpunit": "4.2.*"
|
"phpunit/phpunit": "4.2.*"
|
||||||
|
},
|
||||||
|
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Szurubooru\\Tests\\": "tests/",
|
||||||
|
"Szurubooru\\": "src/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ module.exports = function(grunt) {
|
||||||
},
|
},
|
||||||
|
|
||||||
tests: {
|
tests: {
|
||||||
command: 'php vendor/phpunit/phpunit/phpunit -v --strict --bootstrap src/AutoLoader.php tests/',
|
command: 'php vendor/phpunit/phpunit/phpunit -v --strict --bootstrap src/Bootstrap.php tests/',
|
||||||
},
|
},
|
||||||
|
|
||||||
upgrade: {
|
upgrade: {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
|
||||||
require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'AutoLoader.php');
|
require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Bootstrap.php');
|
||||||
|
|
||||||
|
\Szurubooru\Bootstrap::init();
|
||||||
$httpHelper = \Szurubooru\Injector::get(\Szurubooru\Helpers\HttpHelper::class);
|
$httpHelper = \Szurubooru\Injector::get(\Szurubooru\Helpers\HttpHelper::class);
|
||||||
$dispatcher = \Szurubooru\Injector::get(\Szurubooru\Dispatcher::class);
|
$dispatcher = \Szurubooru\Injector::get(\Szurubooru\Dispatcher::class);
|
||||||
$dispatcher->run($httpHelper->getRequestMethod(), $_GET['q']);
|
$dispatcher->run($httpHelper->getRequestMethod(), $_GET['q']);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
require_once(__DIR__
|
require_once(__DIR__
|
||||||
. DIRECTORY_SEPARATOR . '..'
|
. DIRECTORY_SEPARATOR . '..'
|
||||||
. DIRECTORY_SEPARATOR . 'src'
|
. DIRECTORY_SEPARATOR . 'src'
|
||||||
. DIRECTORY_SEPARATOR . 'AutoLoader.php');
|
. DIRECTORY_SEPARATOR . 'Bootstrap.php');
|
||||||
|
|
||||||
$upgradeService = Szurubooru\Injector::get(\Szurubooru\Services\UpgradeService::class);
|
$upgradeService = Szurubooru\Injector::get(\Szurubooru\Services\UpgradeService::class);
|
||||||
$upgradeService->runUpgradesVerbose();
|
$upgradeService->runUpgradesVerbose();
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Szurubooru;
|
|
||||||
|
|
||||||
final class AutoLoader
|
|
||||||
{
|
|
||||||
public static function init()
|
|
||||||
{
|
|
||||||
spl_autoload_register([__CLASS__, 'includeClassName']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function includeClassName($className)
|
|
||||||
{
|
|
||||||
if (strpos($className, 'Szurubooru') === false)
|
|
||||||
return;
|
|
||||||
$className = str_replace('\\', DIRECTORY_SEPARATOR, $className);
|
|
||||||
$className = str_replace('Szurubooru', '', $className);
|
|
||||||
if (strpos($className, 'Tests') !== false)
|
|
||||||
$className = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('Tests', 'tests', $className);
|
|
||||||
else
|
|
||||||
$className = __DIR__ . DIRECTORY_SEPARATOR . $className;
|
|
||||||
$className .= '.php';
|
|
||||||
include($className);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoLoader::init();
|
|
||||||
|
|
||||||
require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
|
|
||||||
|
|
||||||
function turnErrorsIntoExceptions()
|
|
||||||
{
|
|
||||||
set_error_handler(
|
|
||||||
function($errno, $errstr, $errfile, $errline, array $errcontext)
|
|
||||||
{
|
|
||||||
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
turnErrorsIntoExceptions();
|
|
30
src/Bootstrap.php
Normal file
30
src/Bootstrap.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru;
|
||||||
|
|
||||||
|
final class Bootstrap
|
||||||
|
{
|
||||||
|
public static function init()
|
||||||
|
{
|
||||||
|
self::turnErrorsIntoExceptions();
|
||||||
|
self::initAutoloader();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function initAutoloader()
|
||||||
|
{
|
||||||
|
require(__DIR__
|
||||||
|
. DIRECTORY_SEPARATOR . '..'
|
||||||
|
. DIRECTORY_SEPARATOR . 'vendor'
|
||||||
|
. DIRECTORY_SEPARATOR . 'autoload.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function turnErrorsIntoExceptions()
|
||||||
|
{
|
||||||
|
set_error_handler(
|
||||||
|
function($errno, $errstr, $errfile, $errline, array $errcontext)
|
||||||
|
{
|
||||||
|
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bootstrap::init();
|
|
@ -6,6 +6,7 @@ abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
\Szurubooru\Injector::init();
|
\Szurubooru\Injector::init();
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
|
@ -100,10 +101,3 @@ abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__
|
|
||||||
. DIRECTORY_SEPARATOR . '..'
|
|
||||||
. DIRECTORY_SEPARATOR . 'vendor'
|
|
||||||
. DIRECTORY_SEPARATOR . 'autoload.php';
|
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
|
|
Loading…
Reference in a new issue