summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.php2
-rw-r--r--src/Controllers/KeyController.php2
-rw-r--r--src/Controllers/ServerDiscoveryController.php4
-rw-r--r--src/Controllers/ServerImplementationController.php2
-rw-r--r--src/DB.php6
-rw-r--r--src/ErrorCode.php2
-rw-r--r--src/Router.php22
-rw-r--r--src/Singleton.php4
-rw-r--r--src/routes.php14
9 files changed, 29 insertions, 29 deletions
diff --git a/src/App.php b/src/App.php
index 4c67f76..33f71ef 100644
--- a/src/App.php
+++ b/src/App.php
@@ -11,7 +11,7 @@ class App
$dotenv = new Dotenv();
$dotenv->load(dirname(__DIR__) . "/.env");
}
-
+
public function run(): void
{
Router::getInstance()->run()->send();
diff --git a/src/Controllers/KeyController.php b/src/Controllers/KeyController.php
index bde1642..04f2c6d 100644
--- a/src/Controllers/KeyController.php
+++ b/src/Controllers/KeyController.php
@@ -16,7 +16,7 @@ class KeyController
],
]);
}
-
+
public function query(string $serverName): Response
{}
}
diff --git a/src/Controllers/ServerDiscoveryController.php b/src/Controllers/ServerDiscoveryController.php
index 076329b..c4e5ea7 100644
--- a/src/Controllers/ServerDiscoveryController.php
+++ b/src/Controllers/ServerDiscoveryController.php
@@ -13,7 +13,7 @@ class ServerDiscoveryController
"m.server" => "$_ENV[DOMAIN]:443",
]);
}
-
+
public function client(): Response
{
return new JsonResponse([
@@ -22,7 +22,7 @@ class ServerDiscoveryController
],
]);
}
-
+
public function support(): Response
{
return new JsonResponse([
diff --git a/src/Controllers/ServerImplementationController.php b/src/Controllers/ServerImplementationController.php
index b5d9d0f..e168a65 100644
--- a/src/Controllers/ServerImplementationController.php
+++ b/src/Controllers/ServerImplementationController.php
@@ -16,7 +16,7 @@ class ServerImplementationController
],
]);
}
-
+
public function versions(): Response
{
return new JsonResponse([
diff --git a/src/DB.php b/src/DB.php
index b536079..53d078b 100644
--- a/src/DB.php
+++ b/src/DB.php
@@ -5,9 +5,9 @@ namespace App;
class DB
{
use Singleton;
-
+
private \PDO $connection;
-
+
public function __construct()
{
$driver = $_ENV['DB_DRIVER'] ?? 'pgsql';
@@ -16,7 +16,7 @@ class DB
$dbname = $_ENV['DB_NAME'];
$user = $_ENV['DB_USER'];
$password = $_ENV['DB_PASSWORD'];
-
+
$this->connection = new \PDO("$driver:host=$host;port=$port;dbname=$dbname", $user, $password);
}
}
diff --git a/src/ErrorCode.php b/src/ErrorCode.php
index 048ef34..7a99374 100644
--- a/src/ErrorCode.php
+++ b/src/ErrorCode.php
@@ -6,6 +6,6 @@ enum ErrorCode: string
{
case FORBIDDEN = "M_FORBIDDEN";
case UNKNOWN_TOKEN = "M_UNKNOWN_TOKEN";
-
+
case UNKNOWN = "M_UNKNOWN";
}
diff --git a/src/Router.php b/src/Router.php
index e0b09ad..437d995 100644
--- a/src/Router.php
+++ b/src/Router.php
@@ -12,18 +12,18 @@ use Symfony\Component\Routing\RouteCollection;
class Router
{
use Singleton;
-
+
private RouteCollection $routes;
private RouteConfigurator $configurator;
-
+
public function __construct()
{
$this->routes = new RouteCollection();
$this->configurator = new RouteConfigurator($this->routes, $this->routes);
-
+
$this->addRoutes();
}
-
+
/**
* match the current url against the routes.
* also add preflight CORS headers on OPTIONS requests.
@@ -31,7 +31,7 @@ class Router
public function run(): Response
{
$request = Request::createFromGlobals();
-
+
if ($request->isMethod("OPTIONS")) {
$response = new Response();
$response->headers->add([
@@ -39,26 +39,26 @@ class Router
"Access-Control-Allow-Methods" => "GET, POST, PUT, DELETE, OPTIONS, PATCH, HEAD",
"Access-Control-Allow-Headers" => "X-Requested-With, Content-Type, Authorization",
]);
-
+
return $response;
}
-
+
$context = new RequestContext();
$context->fromRequest($request);
-
+
try {
$matcher = new UrlMatcher($this->routes, $context);
$match = $matcher->matchRequest($request);
-
+
$class = $match["_controller"][0];
$method = $match["_controller"][1];
-
+
return (new $class)->$method();
} catch (\Exception $exception) {
return new ErrorResponse(ErrorCode::UNKNOWN, "Unknown error occured");
}
}
-
+
/**
* add routes from the routes file
*/
diff --git a/src/Singleton.php b/src/Singleton.php
index b4d4598..864da59 100644
--- a/src/Singleton.php
+++ b/src/Singleton.php
@@ -5,13 +5,13 @@ namespace App;
trait Singleton
{
private static self $instance;
-
+
public static function getInstance(): self
{
if (! isset(self::$instance)) {
self::$instance = new self();
}
-
+
return self::$instance;
}
}
diff --git a/src/routes.php b/src/routes.php
index 25e2e1f..21113dc 100644
--- a/src/routes.php
+++ b/src/routes.php
@@ -12,30 +12,30 @@ return function (RouteConfigurator $routes): void
->add("well_known_matrix_server", "/.well-known/matrix/server")
->controller([ServerDiscoveryController::class, "server"])
->methods(["GET"]);
-
+
$routes
->add("well_known_matrix_client", "/.well-known/matrix/client")
->controller([ServerDiscoveryController::class, "client"])
->methods(["GET"]);
-
+
$routes
->add("well_known_matrix_support", "/.well-known/matrix/support")
->controller([ServerDiscoveryController::class, "support"])
->methods(["GET"]);
-
+
$routes
->add("matrix_federation_version", "/_matrix/federation/v1/version")
->controller([ServerImplementationController::class, "version"])
->methods(["GET"]);
-
+
$routes
->add("matrix_client_versions", "/_matrix/client/versions")
->controller([ServerImplementationController::class, "versions"])
->methods(["GET"]);
-
+
# /_matrix/key/v2/server
# /_matrix/key/v2/query
# /_matrix/key/v2/query/{serverName}
-
-
+
+
};