Skip to content

Commit f03a262

Browse files
authored
feat: add implementation of the front controller (#1)
1 parent a0956f2 commit f03a262

6 files changed

Lines changed: 137 additions & 4 deletions

File tree

app/bootstrap.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the sxbrsky/aether.
5+
*
6+
* Copyright (C) 2024 Dominik Szamburski
7+
*
8+
* This software may be modified and distributed under the terms
9+
* of the MIT license. See the LICENSE file for details.
10+
*/
11+
12+
\error_reporting(\E_STRICT | \E_ALL);
13+
14+
if (!\defined('PHP_VERSION_ID') || \PHP_VERSION_ID < 80210) {
15+
echo \PHP_SAPI === 'cli'
16+
? "Unsupported PHP Version, spark supports PHP 8.2.1 or later."
17+
: "<p>Unsupported PHP Version, aether supports PHP 8.2.1 or later.</p>";
18+
19+
\http_response_code(503);
20+
exit(1);
21+
}
22+
23+
if (\PHP_SAPI !== 'cli') {
24+
\ini_set('session.use_cookies', '1');
25+
\ini_set('session.use_only_cookies', '1');
26+
\ini_set('session.use_trans_sid', '0');
27+
\ini_set('session.cache_limiter', '');
28+
\ini_set('session.cookie_httponly', '1');
29+
}
30+
31+
\setlocale(\LC_ALL, 'C');
32+
33+
\mb_internal_encoding('UTF-8');
34+
\mb_language('uni');
35+
36+
\date_default_timezone_set('UTC');
37+
38+
require_once \dirname(__DIR__) . '/vendor/autoload.php';

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"source": "https://github.com/sxbrsky/aether"
88
},
99
"require": {
10-
"php": ">=8.2"
10+
"php": ">=8.2",
11+
"symfony/http-foundation": "^7.1"
1112
},
1213
"require-dev": {
1314
"friendsofphp/php-cs-fixer": "^3.64",
@@ -17,11 +18,15 @@
1718
"minimum-stability": "dev",
1819
"prefer-stable": true,
1920
"autoload": {
20-
"Aether\\Framework\\": "system/Framework"
21+
"psr-4": {
22+
"Aether\\Framework\\": "system/Framework/"
23+
}
2124
},
2225
"autoload-dev": {
23-
"Aehger\\Tests\\PHPStan\\": "dev/phpstan/",
24-
"Aether\\Tests\\Unit\\": "dev/tests/unit/"
26+
"psr-4": {
27+
"Aether\\Tests\\PHPStan\\": "dev/phpstan/",
28+
"Aether\\Tests\\Unit\\": "dev/tests/unit/"
29+
}
2530
},
2631
"config": {
2732
"platform": {

public/index.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,20 @@
88
* This software may be modified and distributed under the terms
99
* of the MIT license. See the LICENSE file for details.
1010
*/
11+
12+
try {
13+
require_once \dirname(__DIR__) . '/app/bootstrap.php';
14+
} catch (\Exception $exc) {
15+
echo "<p>{$exc->getMessage()}" . PHP_EOL;
16+
echo "<p>{$exc->getTraceAsString()}</p>" . PHP_EOL;
17+
18+
exit(1);
19+
}
20+
21+
$kernel = new \Aether\Framework\AetherKernel();
22+
$kernel->start(
23+
new \Aether\Framework\App\Http(
24+
\Symfony\Component\HttpFoundation\Request::createFromGlobals(),
25+
new \Symfony\Component\HttpFoundation\Response()
26+
)
27+
);

system/Framework/AetherKernel.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the sxbrsky/aether.
5+
*
6+
* Copyright (C) 2024 Dominik Szamburski
7+
*
8+
* This software may be modified and distributed under the terms
9+
* of the MIT license. See the LICENSE file for details.
10+
*/
11+
12+
namespace Aether\Framework;
13+
14+
use Aether\Framework\App\AppInterface;
15+
16+
class AetherKernel
17+
{
18+
public function start(AppInterface $application): void
19+
{
20+
$response = $application->run();
21+
$response->send();
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the sxbrsky/aether.
5+
*
6+
* Copyright (C) 2024 Dominik Szamburski
7+
*
8+
* This software may be modified and distributed under the terms
9+
* of the MIT license. See the LICENSE file for details.
10+
*/
11+
12+
namespace Aether\Framework\App;
13+
14+
use Symfony\Component\HttpFoundation\Response;
15+
16+
interface AppInterface
17+
{
18+
public function run(): Response;
19+
}

system/Framework/App/Http.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the sxbrsky/aether.
5+
*
6+
* Copyright (C) 2024 Dominik Szamburski
7+
*
8+
* This software may be modified and distributed under the terms
9+
* of the MIT license. See the LICENSE file for details.
10+
*/
11+
12+
namespace Aether\Framework\App;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
17+
class Http implements AppInterface
18+
{
19+
public function __construct(
20+
private Request $request,
21+
private Response $response,
22+
) {
23+
$this->request = Request::createFromGlobals();
24+
$this->response = new Response();
25+
}
26+
27+
public function run(): Response
28+
{
29+
return $this->response;
30+
}
31+
}

0 commit comments

Comments
 (0)