diff options
| -rw-r--r-- | composer.json | 3 | ||||
| -rw-r--r-- | composer.lock | 564 | ||||
| -rw-r--r-- | src/Controllers/KeyController.php | 10 | ||||
| -rwxr-xr-x | src/Controllers/SyncController.php | 26 | ||||
| -rwxr-xr-x | src/Errors/UnauthorizedError.php | 18 | ||||
| -rw-r--r-- | src/Router/Router.php | 6 | ||||
| -rw-r--r-- | src/Router/routes_client_server.php | 12 | ||||
| -rw-r--r-- | src/Support/Logger.php | 23 | ||||
| -rwxr-xr-x | src/Types/EncryptionAlgorithm.php | 9 | 
9 files changed, 668 insertions, 3 deletions
| diff --git a/composer.json b/composer.json index ab896e9..48ff46e 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@      "require": {          "symfony/dotenv": "^7.3",          "symfony/http-foundation": "^7.3", -        "symfony/routing": "^7.3" +        "symfony/routing": "^7.3", +        "symfony/expression-language": "^7.3"      },      "require-dev": {          "guzzlehttp/guzzle": "^7.9", diff --git a/composer.lock b/composer.lock index 774a7d5..914b915 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,339 @@          "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",          "This file is @generated automatically"      ], -    "content-hash": "5257909e0eb2132c25ac43ca35aefbb1", +    "content-hash": "c0a99656a34ec28749287e0a3fed54b4",      "packages": [          { +            "name": "psr/cache", +            "version": "3.0.0", +            "source": { +                "type": "git", +                "url": "https://github.com/php-fig/cache.git", +                "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf" +            }, +            "dist": { +                "type": "zip", +                "url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", +                "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", +                "shasum": "" +            }, +            "require": { +                "php": ">=8.0.0" +            }, +            "type": "library", +            "extra": { +                "branch-alias": { +                    "dev-master": "1.0.x-dev" +                } +            }, +            "autoload": { +                "psr-4": { +                    "Psr\\Cache\\": "src/" +                } +            }, +            "notification-url": "https://packagist.org/downloads/", +            "license": [ +                "MIT" +            ], +            "authors": [ +                { +                    "name": "PHP-FIG", +                    "homepage": "https://www.php-fig.org/" +                } +            ], +            "description": "Common interface for caching libraries", +            "keywords": [ +                "cache", +                "psr", +                "psr-6" +            ], +            "support": { +                "source": "https://github.com/php-fig/cache/tree/3.0.0" +            }, +            "time": "2021-02-03T23:26:27+00:00" +        }, +        { +            "name": "psr/container", +            "version": "2.0.2", +            "source": { +                "type": "git", +                "url": "https://github.com/php-fig/container.git", +                "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" +            }, +            "dist": { +                "type": "zip", +                "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", +                "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", +                "shasum": "" +            }, +            "require": { +                "php": ">=7.4.0" +            }, +            "type": "library", +            "extra": { +                "branch-alias": { +                    "dev-master": "2.0.x-dev" +                } +            }, +            "autoload": { +                "psr-4": { +                    "Psr\\Container\\": "src/" +                } +            }, +            "notification-url": "https://packagist.org/downloads/", +            "license": [ +                "MIT" +            ], +            "authors": [ +                { +                    "name": "PHP-FIG", +                    "homepage": "https://www.php-fig.org/" +                } +            ], +            "description": "Common Container Interface (PHP FIG PSR-11)", +            "homepage": "https://github.com/php-fig/container", +            "keywords": [ +                "PSR-11", +                "container", +                "container-interface", +                "container-interop", +                "psr" +            ], +            "support": { +                "issues": "https://github.com/php-fig/container/issues", +                "source": "https://github.com/php-fig/container/tree/2.0.2" +            }, +            "time": "2021-11-05T16:47:00+00:00" +        }, +        { +            "name": "psr/log", +            "version": "3.0.2", +            "source": { +                "type": "git", +                "url": "https://github.com/php-fig/log.git", +                "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3" +            }, +            "dist": { +                "type": "zip", +                "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", +                "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", +                "shasum": "" +            }, +            "require": { +                "php": ">=8.0.0" +            }, +            "type": "library", +            "extra": { +                "branch-alias": { +                    "dev-master": "3.x-dev" +                } +            }, +            "autoload": { +                "psr-4": { +                    "Psr\\Log\\": "src" +                } +            }, +            "notification-url": "https://packagist.org/downloads/", +            "license": [ +                "MIT" +            ], +            "authors": [ +                { +                    "name": "PHP-FIG", +                    "homepage": "https://www.php-fig.org/" +                } +            ], +            "description": "Common interface for logging libraries", +            "homepage": "https://github.com/php-fig/log", +            "keywords": [ +                "log", +                "psr", +                "psr-3" +            ], +            "support": { +                "source": "https://github.com/php-fig/log/tree/3.0.2" +            }, +            "time": "2024-09-11T13:17:53+00:00" +        }, +        { +            "name": "symfony/cache", +            "version": "v7.3.2", +            "source": { +                "type": "git", +                "url": "https://github.com/symfony/cache.git", +                "reference": "6621a2bee5373e3e972b2ae5dbedd5ac899d8cb6" +            }, +            "dist": { +                "type": "zip", +                "url": "https://api.github.com/repos/symfony/cache/zipball/6621a2bee5373e3e972b2ae5dbedd5ac899d8cb6", +                "reference": "6621a2bee5373e3e972b2ae5dbedd5ac899d8cb6", +                "shasum": "" +            }, +            "require": { +                "php": ">=8.2", +                "psr/cache": "^2.0|^3.0", +                "psr/log": "^1.1|^2|^3", +                "symfony/cache-contracts": "^3.6", +                "symfony/deprecation-contracts": "^2.5|^3.0", +                "symfony/service-contracts": "^2.5|^3", +                "symfony/var-exporter": "^6.4|^7.0" +            }, +            "conflict": { +                "doctrine/dbal": "<3.6", +                "symfony/dependency-injection": "<6.4", +                "symfony/http-kernel": "<6.4", +                "symfony/var-dumper": "<6.4" +            }, +            "provide": { +                "psr/cache-implementation": "2.0|3.0", +                "psr/simple-cache-implementation": "1.0|2.0|3.0", +                "symfony/cache-implementation": "1.1|2.0|3.0" +            }, +            "require-dev": { +                "cache/integration-tests": "dev-master", +                "doctrine/dbal": "^3.6|^4", +                "predis/predis": "^1.1|^2.0", +                "psr/simple-cache": "^1.0|^2.0|^3.0", +                "symfony/clock": "^6.4|^7.0", +                "symfony/config": "^6.4|^7.0", +                "symfony/dependency-injection": "^6.4|^7.0", +                "symfony/filesystem": "^6.4|^7.0", +                "symfony/http-kernel": "^6.4|^7.0", +                "symfony/messenger": "^6.4|^7.0", +                "symfony/var-dumper": "^6.4|^7.0" +            }, +            "type": "library", +            "autoload": { +                "psr-4": { +                    "Symfony\\Component\\Cache\\": "" +                }, +                "classmap": [ +                    "Traits/ValueWrapper.php" +                ], +                "exclude-from-classmap": [ +                    "/Tests/" +                ] +            }, +            "notification-url": "https://packagist.org/downloads/", +            "license": [ +                "MIT" +            ], +            "authors": [ +                { +                    "name": "Nicolas Grekas", +                    "email": "p@tchwork.com" +                }, +                { +                    "name": "Symfony Community", +                    "homepage": "https://symfony.com/contributors" +                } +            ], +            "description": "Provides extended PSR-6, PSR-16 (and tags) implementations", +            "homepage": "https://symfony.com", +            "keywords": [ +                "caching", +                "psr6" +            ], +            "support": { +                "source": "https://github.com/symfony/cache/tree/v7.3.2" +            }, +            "funding": [ +                { +                    "url": "https://symfony.com/sponsor", +                    "type": "custom" +                }, +                { +                    "url": "https://github.com/fabpot", +                    "type": "github" +                }, +                { +                    "url": "https://github.com/nicolas-grekas", +                    "type": "github" +                }, +                { +                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", +                    "type": "tidelift" +                } +            ], +            "time": "2025-07-30T17:13:41+00:00" +        }, +        { +            "name": "symfony/cache-contracts", +            "version": "v3.6.0", +            "source": { +                "type": "git", +                "url": "https://github.com/symfony/cache-contracts.git", +                "reference": "5d68a57d66910405e5c0b63d6f0af941e66fc868" +            }, +            "dist": { +                "type": "zip", +                "url": "https://api.github.com/repos/symfony/cache-contracts/zipball/5d68a57d66910405e5c0b63d6f0af941e66fc868", +                "reference": "5d68a57d66910405e5c0b63d6f0af941e66fc868", +                "shasum": "" +            }, +            "require": { +                "php": ">=8.1", +                "psr/cache": "^3.0" +            }, +            "type": "library", +            "extra": { +                "thanks": { +                    "url": "https://github.com/symfony/contracts", +                    "name": "symfony/contracts" +                }, +                "branch-alias": { +                    "dev-main": "3.6-dev" +                } +            }, +            "autoload": { +                "psr-4": { +                    "Symfony\\Contracts\\Cache\\": "" +                } +            }, +            "notification-url": "https://packagist.org/downloads/", +            "license": [ +                "MIT" +            ], +            "authors": [ +                { +                    "name": "Nicolas Grekas", +                    "email": "p@tchwork.com" +                }, +                { +                    "name": "Symfony Community", +                    "homepage": "https://symfony.com/contributors" +                } +            ], +            "description": "Generic abstractions related to caching", +            "homepage": "https://symfony.com", +            "keywords": [ +                "abstractions", +                "contracts", +                "decoupling", +                "interfaces", +                "interoperability", +                "standards" +            ], +            "support": { +                "source": "https://github.com/symfony/cache-contracts/tree/v3.6.0" +            }, +            "funding": [ +                { +                    "url": "https://symfony.com/sponsor", +                    "type": "custom" +                }, +                { +                    "url": "https://github.com/fabpot", +                    "type": "github" +                }, +                { +                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", +                    "type": "tidelift" +                } +            ], +            "time": "2025-03-13T15:25:07+00:00" +        }, +        {              "name": "symfony/deprecation-contracts",              "version": "v3.6.0",              "source": { @@ -152,6 +482,74 @@              "time": "2025-07-10T08:29:33+00:00"          },          { +            "name": "symfony/expression-language", +            "version": "v7.3.2", +            "source": { +                "type": "git", +                "url": "https://github.com/symfony/expression-language.git", +                "reference": "32d2d19c62e58767e6552166c32fb259975d2b23" +            }, +            "dist": { +                "type": "zip", +                "url": "https://api.github.com/repos/symfony/expression-language/zipball/32d2d19c62e58767e6552166c32fb259975d2b23", +                "reference": "32d2d19c62e58767e6552166c32fb259975d2b23", +                "shasum": "" +            }, +            "require": { +                "php": ">=8.2", +                "symfony/cache": "^6.4|^7.0", +                "symfony/deprecation-contracts": "^2.5|^3", +                "symfony/service-contracts": "^2.5|^3" +            }, +            "type": "library", +            "autoload": { +                "psr-4": { +                    "Symfony\\Component\\ExpressionLanguage\\": "" +                }, +                "exclude-from-classmap": [ +                    "/Tests/" +                ] +            }, +            "notification-url": "https://packagist.org/downloads/", +            "license": [ +                "MIT" +            ], +            "authors": [ +                { +                    "name": "Fabien Potencier", +                    "email": "fabien@symfony.com" +                }, +                { +                    "name": "Symfony Community", +                    "homepage": "https://symfony.com/contributors" +                } +            ], +            "description": "Provides an engine that can compile and evaluate expressions", +            "homepage": "https://symfony.com", +            "support": { +                "source": "https://github.com/symfony/expression-language/tree/v7.3.2" +            }, +            "funding": [ +                { +                    "url": "https://symfony.com/sponsor", +                    "type": "custom" +                }, +                { +                    "url": "https://github.com/fabpot", +                    "type": "github" +                }, +                { +                    "url": "https://github.com/nicolas-grekas", +                    "type": "github" +                }, +                { +                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", +                    "type": "tidelift" +                } +            ], +            "time": "2025-07-10T08:29:33+00:00" +        }, +        {              "name": "symfony/http-foundation",              "version": "v7.3.2",              "source": { @@ -475,6 +873,170 @@                  }              ],              "time": "2025-07-15T11:36:08+00:00" +        }, +        { +            "name": "symfony/service-contracts", +            "version": "v3.6.0", +            "source": { +                "type": "git", +                "url": "https://github.com/symfony/service-contracts.git", +                "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4" +            }, +            "dist": { +                "type": "zip", +                "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4", +                "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4", +                "shasum": "" +            }, +            "require": { +                "php": ">=8.1", +                "psr/container": "^1.1|^2.0", +                "symfony/deprecation-contracts": "^2.5|^3" +            }, +            "conflict": { +                "ext-psr": "<1.1|>=2" +            }, +            "type": "library", +            "extra": { +                "thanks": { +                    "url": "https://github.com/symfony/contracts", +                    "name": "symfony/contracts" +                }, +                "branch-alias": { +                    "dev-main": "3.6-dev" +                } +            }, +            "autoload": { +                "psr-4": { +                    "Symfony\\Contracts\\Service\\": "" +                }, +                "exclude-from-classmap": [ +                    "/Test/" +                ] +            }, +            "notification-url": "https://packagist.org/downloads/", +            "license": [ +                "MIT" +            ], +            "authors": [ +                { +                    "name": "Nicolas Grekas", +                    "email": "p@tchwork.com" +                }, +                { +                    "name": "Symfony Community", +                    "homepage": "https://symfony.com/contributors" +                } +            ], +            "description": "Generic abstractions related to writing services", +            "homepage": "https://symfony.com", +            "keywords": [ +                "abstractions", +                "contracts", +                "decoupling", +                "interfaces", +                "interoperability", +                "standards" +            ], +            "support": { +                "source": "https://github.com/symfony/service-contracts/tree/v3.6.0" +            }, +            "funding": [ +                { +                    "url": "https://symfony.com/sponsor", +                    "type": "custom" +                }, +                { +                    "url": "https://github.com/fabpot", +                    "type": "github" +                }, +                { +                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", +                    "type": "tidelift" +                } +            ], +            "time": "2025-04-25T09:37:31+00:00" +        }, +        { +            "name": "symfony/var-exporter", +            "version": "v7.3.2", +            "source": { +                "type": "git", +                "url": "https://github.com/symfony/var-exporter.git", +                "reference": "05b3e90654c097817325d6abd284f7938b05f467" +            }, +            "dist": { +                "type": "zip", +                "url": "https://api.github.com/repos/symfony/var-exporter/zipball/05b3e90654c097817325d6abd284f7938b05f467", +                "reference": "05b3e90654c097817325d6abd284f7938b05f467", +                "shasum": "" +            }, +            "require": { +                "php": ">=8.2", +                "symfony/deprecation-contracts": "^2.5|^3" +            }, +            "require-dev": { +                "symfony/property-access": "^6.4|^7.0", +                "symfony/serializer": "^6.4|^7.0", +                "symfony/var-dumper": "^6.4|^7.0" +            }, +            "type": "library", +            "autoload": { +                "psr-4": { +                    "Symfony\\Component\\VarExporter\\": "" +                }, +                "exclude-from-classmap": [ +                    "/Tests/" +                ] +            }, +            "notification-url": "https://packagist.org/downloads/", +            "license": [ +                "MIT" +            ], +            "authors": [ +                { +                    "name": "Nicolas Grekas", +                    "email": "p@tchwork.com" +                }, +                { +                    "name": "Symfony Community", +                    "homepage": "https://symfony.com/contributors" +                } +            ], +            "description": "Allows exporting any serializable PHP data structure to plain PHP code", +            "homepage": "https://symfony.com", +            "keywords": [ +                "clone", +                "construct", +                "export", +                "hydrate", +                "instantiate", +                "lazy-loading", +                "proxy", +                "serialize" +            ], +            "support": { +                "source": "https://github.com/symfony/var-exporter/tree/v7.3.2" +            }, +            "funding": [ +                { +                    "url": "https://symfony.com/sponsor", +                    "type": "custom" +                }, +                { +                    "url": "https://github.com/fabpot", +                    "type": "github" +                }, +                { +                    "url": "https://github.com/nicolas-grekas", +                    "type": "github" +                }, +                { +                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", +                    "type": "tidelift" +                } +            ], +            "time": "2025-07-10T08:47:49+00:00"          }      ],      "packages-dev": [ diff --git a/src/Controllers/KeyController.php b/src/Controllers/KeyController.php index 04f2c6d..a999e40 100644 --- a/src/Controllers/KeyController.php +++ b/src/Controllers/KeyController.php @@ -2,6 +2,7 @@  namespace App\Controllers; +use Symfony\Component\HttpFoundation\Request;  use Symfony\Component\HttpFoundation\Response;  use Symfony\Component\HttpFoundation\JsonResponse; @@ -17,6 +18,15 @@ class KeyController      ]);    } +  public function upload(): Response +  { +    $request = Request::createFromGlobals(); + +    return new JsonResponse([ +      "one_time_key_counts" => [], +    ]); +  } +    public function query(string $serverName): Response    {}  } diff --git a/src/Controllers/SyncController.php b/src/Controllers/SyncController.php new file mode 100755 index 0000000..19da1b5 --- /dev/null +++ b/src/Controllers/SyncController.php @@ -0,0 +1,26 @@ +<?php + +namespace App\Controllers; + +use App\Errors\UnauthorizedError; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\JsonResponse; + +class SyncController +{ +  public function sync(): Response +  { +    $request = Request::createFromGlobals(); + +    if ($request->headers->get("authorization") != "Bearer abc123") { +      # TODO: get user based on bearer token +      throw new UnauthorizedError(); +    } + +    return new JsonResponse([ +      "account_data" => [], +      "next_batch" => "", +    ]); +  } +} diff --git a/src/Errors/UnauthorizedError.php b/src/Errors/UnauthorizedError.php new file mode 100755 index 0000000..97df025 --- /dev/null +++ b/src/Errors/UnauthorizedError.php @@ -0,0 +1,18 @@ +<?php + +namespace App\Errors; + +use Symfony\Component\HttpFoundation\Response; + +class UnauthorizedError extends Exception +{ +  public function __construct() +  { +    parent::__construct(ErrorCode::FORBIDDEN, "Unauthorized", Response::HTTP_UNAUTHORIZED); +  } + +  public function getAdditionalData(): array +  { +    return []; +  } +} diff --git a/src/Router/Router.php b/src/Router/Router.php index b167142..1739e7c 100644 --- a/src/Router/Router.php +++ b/src/Router/Router.php @@ -67,7 +67,11 @@ class Router      } catch (MethodNotAllowedException $exception) {        return new ErrorResponse(ErrorCode::FORBIDDEN, "403", Response::HTTP_FORBIDDEN);      } catch (\Exception $exception) { -      return new ErrorResponse(ErrorCode::UNKNOWN, "Unknown error occured", Response::HTTP_INTERNAL_SERVER_ERROR); +      return new ErrorResponse( +        ErrorCode::UNKNOWN, +        $exception->getMessage() ?: "Unknown error occured", +        Response::HTTP_INTERNAL_SERVER_ERROR +      );      }    } diff --git a/src/Router/routes_client_server.php b/src/Router/routes_client_server.php index eff0be5..78e2e48 100644 --- a/src/Router/routes_client_server.php +++ b/src/Router/routes_client_server.php @@ -2,9 +2,11 @@  namespace App\Router; +use App\Controllers\KeyController;  use App\Controllers\LoginController;  use App\Controllers\ServerDiscoveryController;  use App\Controllers\ServerImplementationController; +use App\Controllers\SyncController;  use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator;  return function (RouteConfigurator $routes): void @@ -38,4 +40,14 @@ return function (RouteConfigurator $routes): void      ->add("matrix_client_v3_login", "/_matrix/client/v3/login")      ->controller([LoginController::class, "login"])      ->methods(["POST"]); + +  $routes +    ->add("matrix_client_v3_keys_upload", "/_matrix/client/v3/keys/upload") +    ->controller([KeyController::class, "upload"]) +    ->methods(["POST"]); + +  $routes +    ->add("matrix_client_v3_sync", "/_matrix/client/v3/sync") +    ->controller([SyncController::class, "sync"]) +    ->methods(["GET"]);  }; diff --git a/src/Support/Logger.php b/src/Support/Logger.php new file mode 100644 index 0000000..fb86166 --- /dev/null +++ b/src/Support/Logger.php @@ -0,0 +1,23 @@ +<?php + +namespace App\Support; + +use Symfony\Component\HttpFoundation\Request; + +class Logger +{ +  public static function logRequestToFile(Request $request): void +  { +    $basePath = dirname(dirname(__DIR__)) . "/.phpunit.cache/" . str_replace("/", "_", $request->getPathInfo()); + +    file_put_contents( +      $basePath . "-body.json", +      $request->getContent() +    ); + +    file_put_contents( +      $basePath . "-header.json", +      json_encode($request->headers->all()) +    ); +  } +} diff --git a/src/Types/EncryptionAlgorithm.php b/src/Types/EncryptionAlgorithm.php new file mode 100755 index 0000000..5ee89e4 --- /dev/null +++ b/src/Types/EncryptionAlgorithm.php @@ -0,0 +1,9 @@ +<?php + +namespace App\Types; + +enum EncryptionAlgorithm: string +{ +  case A = "m.olm.v1.curve25519-aes-sha2"; +  case B = "m.megolm.v1.aes-sha2"; +} | 
