Moved autoloader to composer config

This commit is contained in:
Marcin Kurczewski 2014-10-02 19:19:55 +02:00
parent 7cb2588eca
commit 216d9b3001
7 changed files with 43 additions and 49 deletions

View file

@ -7,5 +7,12 @@
"require-dev": {
"jbrooksuk/phpcheckstyle": "dev-master",
"phpunit/phpunit": "4.2.*"
},
"autoload": {
"psr-4": {
"Szurubooru\\Tests\\": "tests/",
"Szurubooru\\": "src/"
}
}
}

View file

@ -79,7 +79,7 @@ module.exports = function(grunt) {
},
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: {

View file

@ -1,7 +1,9 @@
<?php
$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);
$dispatcher = \Szurubooru\Injector::get(\Szurubooru\Dispatcher::class);
$dispatcher->run($httpHelper->getRequestMethod(), $_GET['q']);

View file

@ -2,7 +2,7 @@
require_once(__DIR__
. DIRECTORY_SEPARATOR . '..'
. DIRECTORY_SEPARATOR . 'src'
. DIRECTORY_SEPARATOR . 'AutoLoader.php');
. DIRECTORY_SEPARATOR . 'Bootstrap.php');
$upgradeService = Szurubooru\Injector::get(\Szurubooru\Services\UpgradeService::class);
$upgradeService->runUpgradesVerbose();

View file

@ -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
View 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();

View file

@ -6,6 +6,7 @@ abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
protected function setUp()
{
\Szurubooru\Injector::init();
date_default_timezone_set('UTC');
}
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');