Removed controller layer
This commit is contained in:
parent
e38152b921
commit
3245c75187
6 changed files with 2 additions and 58 deletions
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
namespace Szurubooru;
|
||||
|
||||
class ControllerRepository
|
||||
{
|
||||
private $controllers = [];
|
||||
|
||||
public function __construct(array $controllers)
|
||||
{
|
||||
$this->controllers = $controllers;
|
||||
}
|
||||
|
||||
public function getControllers()
|
||||
{
|
||||
return $this->controllers;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
namespace Szurubooru\Controllers;
|
||||
use Szurubooru\Router;
|
||||
|
||||
abstract class AbstractController
|
||||
{
|
||||
abstract function registerRoutes(Router $router);
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
namespace Szurubooru;
|
||||
use Szurubooru\Bootstrap;
|
||||
use Szurubooru\Config;
|
||||
use Szurubooru\ControllerRepository;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
use Szurubooru\Helpers\HttpHelper;
|
||||
use Szurubooru\Router;
|
||||
|
@ -24,8 +23,7 @@ final class Dispatcher
|
|||
HttpHelper $httpHelper,
|
||||
AuthService $authService,
|
||||
TokenService $tokenService,
|
||||
RouteRepository $routeRepository,
|
||||
ControllerRepository $controllerRepository)
|
||||
RouteRepository $routeRepository)
|
||||
{
|
||||
$this->router = $router;
|
||||
$this->config = $config;
|
||||
|
@ -37,9 +35,6 @@ final class Dispatcher
|
|||
//if script fails prematurely, mark it as fail from advance
|
||||
$this->httpHelper->setResponseCode(500);
|
||||
|
||||
foreach ($controllerRepository->getControllers() as $controller)
|
||||
$controller->registerRoutes($router);
|
||||
|
||||
$routeRepository->injectRoutes($router);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ return [
|
|||
\Szurubooru\Config::class => DI\object()->constructor($dataDirectory, $publicDataDirectory),
|
||||
|
||||
\Szurubooru\RouteRepository::class => DI\object()->constructor(DI\link('routes')),
|
||||
\Szurubooru\ControllerRepository::class => DI\object()->constructor(DI\link('controllers')),
|
||||
\Szurubooru\Upgrades\UpgradeRepository::class => DI\object()->constructor(DI\link('upgrades')),
|
||||
|
||||
'upgrades' => DI\factory(function (DI\container $container) {
|
||||
|
@ -55,11 +54,6 @@ return [
|
|||
];
|
||||
}),
|
||||
|
||||
'controllers' => DI\factory(function (DI\container $container) {
|
||||
return [
|
||||
];
|
||||
}),
|
||||
|
||||
'routes' => DI\factory(function (DI\container $container) {
|
||||
return [
|
||||
$container->get(\Szurubooru\Routes\Login::class),
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
namespace Szurubooru\Tests;
|
||||
use Szurubooru\Injector;
|
||||
use Szurubooru\Tests\AbstractTestCase;
|
||||
|
||||
final class ControllerRepositoryTest extends AbstractDatabaseTestCase
|
||||
{
|
||||
public function testInjection()
|
||||
{
|
||||
$controllerRepository = Injector::get(\Szurubooru\ControllerRepository::class);
|
||||
$this->assertNotEmpty($controllerRepository->getControllers());
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
namespace Szurubooru\Tests;
|
||||
use Szurubooru\ControllerRepository;
|
||||
use Szurubooru\Dispatcher;
|
||||
use Szurubooru\Helpers\HttpHelper;
|
||||
use Szurubooru\RouteRepository;
|
||||
|
@ -16,7 +15,6 @@ final class DispatcherTest extends AbstractDatabaseTestCase
|
|||
private $httpHelperMock;
|
||||
private $authServiceMock;
|
||||
private $tokenServiceMock;
|
||||
private $controllerRepositoryMock;
|
||||
private $routeRepositoryMock;
|
||||
|
||||
public function setUp()
|
||||
|
@ -27,7 +25,6 @@ final class DispatcherTest extends AbstractDatabaseTestCase
|
|||
$this->httpHelperMock = $this->mock(HttpHelper::class);
|
||||
$this->authServiceMock = $this->mock(AuthService::class);
|
||||
$this->tokenServiceMock = $this->mock(TokenService::class);
|
||||
$this->controllerRepositoryMock = $this->mock(ControllerRepository::class);
|
||||
$this->routeRepositoryMock = $this->mock(RouteRepository::class);
|
||||
$this->configMock->set('misc/dumpSqlIntoQueries', 0);
|
||||
}
|
||||
|
@ -41,7 +38,6 @@ final class DispatcherTest extends AbstractDatabaseTestCase
|
|||
->method('setResponseCode')
|
||||
->withConsecutive([$this->equalTo(500)], [$this->equalTo(200)]);
|
||||
$this->routerMock->expects($this->once())->method('handle')->willReturn($expected);
|
||||
$this->controllerRepositoryMock->method('getControllers')->willReturn([]);
|
||||
$this->routeRepositoryMock->expects($this->once())->method('injectRoutes');
|
||||
|
||||
$dispatcher = $this->getDispatcher();
|
||||
|
@ -58,7 +54,6 @@ final class DispatcherTest extends AbstractDatabaseTestCase
|
|||
$expected = ['bunny' => 5];
|
||||
|
||||
$this->routerMock->expects($this->once())->method('handle')->willReturn($classData);
|
||||
$this->controllerRepositoryMock->method('getControllers')->willReturn([]);
|
||||
$this->routeRepositoryMock->expects($this->once())->method('injectRoutes');
|
||||
|
||||
$dispatcher = $this->getDispatcher();
|
||||
|
@ -72,7 +67,6 @@ final class DispatcherTest extends AbstractDatabaseTestCase
|
|||
{
|
||||
$this->httpHelperMock->expects($this->once())->method('getRequestHeader')->with($this->equalTo('X-Authorization-Token'))->willReturn('test');
|
||||
$this->tokenServiceMock->expects($this->once())->method('getByName');
|
||||
$this->controllerRepositoryMock->method('getControllers')->willReturn([]);
|
||||
$this->routeRepositoryMock->expects($this->once())->method('injectRoutes');
|
||||
|
||||
$dispatcher = $this->getDispatcher();
|
||||
|
@ -88,7 +82,6 @@ final class DispatcherTest extends AbstractDatabaseTestCase
|
|||
$this->httpHelperMock,
|
||||
$this->authServiceMock,
|
||||
$this->tokenServiceMock,
|
||||
$this->routeRepositoryMock,
|
||||
$this->controllerRepositoryMock);
|
||||
$this->routeRepositoryMock);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue