Skip to content

Commit c43d55e

Browse files
authored
Merge pull request #346 from MightyCreak/refactor/move-http-request
refactor: move HttpRequest member to RssController
2 parents 4528c42 + cd342e3 commit c43d55e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/Controller/RssController.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
use Suin\RSSWriter\Feed as RSSFeed;
77
use Suin\RSSWriter\Channel as RSSChannel;
88
use Suin\RSSWriter\Item as RSSItem;
9+
use Symfony\Component\HttpFoundation\Request as HttpRequest;
910
use Symfony\Component\HttpFoundation\Response as HttpResponse;
1011

1112
class RssController
1213
{
14+
private readonly HttpRequest $request;
15+
16+
public function __construct()
17+
{
18+
$this->request = HttpRequest::createFromGlobals();
19+
}
20+
1321
public function run(): void
1422
{
1523
$featuresXmlFilepath = Mesamatrix::path(Mesamatrix::$config->getValue("info", "xml_file"));
@@ -43,7 +51,7 @@ public function run(): void
4351
['Content-Type' => 'text/xml']
4452
);
4553

46-
$response->prepare(Mesamatrix::$request);
54+
$response->prepare($this->request);
4755
$response->send();
4856
}
4957

@@ -79,8 +87,8 @@ private function generateRss(string $featuresXmlFilepath): ?string
7987
// prepare RSS
8088
$rss = new RSSFeed();
8189

82-
$baseUrl = Mesamatrix::$request->getSchemeAndHttpHost()
83-
. Mesamatrix::$request->getBasePath();
90+
$baseUrl = $this->request->getSchemeAndHttpHost()
91+
. $this->request->getBasePath();
8492

8593
$channel = new RSSChannel();
8694
$channel

src/Mesamatrix.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
use Monolog\ErrorHandler;
2727
use Monolog\Handler\ErrorLogHandler;
2828
use Monolog\Handler\StreamHandler;
29-
use Symfony\Component\HttpFoundation\Request as HttpRequest;
3029

3130
class Mesamatrix
3231
{
3332
public static string $serverRoot; // Path to root of installation
3433
public static string $configDir; // Path to configuration directory
3534
public static Config $config;
3635
public static Logger $logger;
37-
public static HttpRequest $request;
3836

3937
public static function init()
4038
{
@@ -82,9 +80,6 @@ public static function init()
8280
exit(1);
8381
}
8482

85-
// Initialize request
86-
self::$request = HttpRequest::createFromGlobals();
87-
8883
self::$logger->debug('Base initialization complete');
8984

9085
self::$logger->debug('Log level: ' . Logger::toMonologLevel($logLevel)->getName());

0 commit comments

Comments
 (0)