Fix tests & Router is now using Dependency Injection instead of DI Registry

This commit is contained in:
nupplaPhil 2020-01-19 22:38:33 +01:00
parent d5a473abda
commit f9d0e57f91
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
12 changed files with 54 additions and 29 deletions

View file

@ -8,7 +8,7 @@ use FastRoute\Dispatcher;
use FastRoute\RouteCollector;
use FastRoute\RouteParser\Std;
use Friendica\Core\Hook;
use Friendica\DI;
use Friendica\Core\L10n;
use Friendica\Network\HTTPException;
/**
@ -44,12 +44,18 @@ class Router
*/
private $parameters = [];
/** @var L10n */
private $l10n;
/**
* @param array $server The $_SERVER variable
* @param L10n $l10n
* @param RouteCollector|null $routeCollector Optional the loaded Route collector
*/
public function __construct(array $server, RouteCollector $routeCollector = null)
public function __construct(array $server, L10n $l10n, RouteCollector $routeCollector = null)
{
$this->l10n = $l10n;
$httpMethod = $server['REQUEST_METHOD'] ?? self::GET;
$this->httpMethod = in_array($httpMethod, self::ALLOWED_METHODS) ? $httpMethod : self::GET;
@ -181,9 +187,9 @@ class Router
$moduleClass = $routeInfo[1];
$this->parameters = $routeInfo[2];
} elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
throw new HTTPException\MethodNotAllowedException(DI::l10n()->t('Method not allowed for this module. Allowed method(s): %s', implode(', ', $routeInfo[1])));
throw new HTTPException\MethodNotAllowedException($this->l10n->t('Method not allowed for this module. Allowed method(s): %s', implode(', ', $routeInfo[1])));
} else {
throw new HTTPException\NotFoundException(DI::l10n()->t('Page not found.'));
throw new HTTPException\NotFoundException($this->l10n->t('Page not found.'));
}
return $moduleClass;