Exemplo n.º 1
0
<?php

declare (strict_types=1);
namespace Amplify;

use Aerys\Request;
use Aerys\Response;
use function Aerys\router;
use function Aerys\websocket;
$router = router()->route('GET', '/', function (Request $request, Response $response) use($template) {
    $response->send(file_get_contents(__DIR__ . '/templates/page.phtml'));
})->route('GET', '/ws', websocket(new Handler(), ["maxBytesPerMinute" => 1 << 26, "maxFramesPerSecond" => 1000000]))->route('GET', '/stop', function () {
    \Amp\stop();
});
Exemplo n.º 2
0
<?php

use Auryn\Injector;
use function Aerys\router;
$config = (require __DIR__ . "/config/config.php");
$injector = new Injector();
$injector->share(new \Amp\Mysql\Pool(sprintf("host=%s;user=%s;pass=%s;db=%s", $config["database"]["host"], $config["database"]["user"], $config["database"]["pass"], $config["database"]["name"])));
$injector->alias("Kelunik\\Chat\\Integration\\HookRepository", "Kelunik\\Chat\\Integration\\MysqlHookRepository");
$handler = $injector->make("Kelunik\\Chat\\Integration\\Dispatcher", [":config" => $config]);
$router = router();
$router->post("{service}/{id:[0-9]+}", [$handler, "handle"]);
$host = (new Aerys\Host())->expose("*", $config["deploy"]["port"])->name($config["deploy"]["host"])->use($router);
Exemplo n.º 3
0
 private function buildRouter()
 {
     $this->router = router()->route('GET', '/rooms', [$this, 'getAllRooms'])->route('GET', '/rooms/' . self::ROOM_IDENTIFIER_EXPR, [$this, 'getRoomInfo'])->route('GET', '/rooms/' . self::ROOM_IDENTIFIER_EXPR . '/bans', [$this, 'getRoomBans'])->route('POST', '/rooms/' . self::ROOM_IDENTIFIER_EXPR . '/ban', [$this, 'banUserInRoom'])->route('POST', '/rooms/' . self::ROOM_IDENTIFIER_EXPR . '/unban', [$this, 'unbanUserInRoom']);
 }
Exemplo n.º 4
0
$injector->alias("Kelunik\\Chat\\Search\\Messages\\MessageSearch", "Kelunik\\Chat\\Search\\Messages\\ElasticSearch");
$injector->prepare("Kelunik\\Template\\TemplateService", function (TemplateService $service) {
    $service->setBaseDirectory(__DIR__ . "/../res/html");
});
$injector->define("Kelunik\\Chat\\Search\\Messages\\ElasticSearch", [":host" => config("elastic.host"), ":port" => config("elastic.port")]);
$injector->share($injector);
$injector->share("Kelunik\\Template\\TemplateService");
$injector->share(new Redis(config("redis.protocol") . "://" . config("redis.host") . ":" . config("redis.port")));
$injector->share(new SubscribeClient(config("redis.protocol") . "://" . config("redis.host") . ":" . config("redis.port")));
$injector->share(new MySQL(sprintf("host=%s;user=%s;pass=%s;db=%s", config("database.host"), config("database.user"), config("database.pass"), config("database.name"))));
$auth = $injector->make("Kelunik\\ChatMain\\Auth");
/** @var TemplateService $templateService */
$templateService = $injector->make("Kelunik\\Template\\TemplateService");
/** @var Chat $chat */
$chat = $injector->make("Kelunik\\Chat\\Chat");
$router = router()->get("", function (Request $req, Response $resp) use($templateService) {
    $session = (yield (new Session($req))->read());
    if (!$session->get("login")) {
        $template = $templateService->load("main.php");
        $resp->send($template->render());
    }
})->get("login", [$auth, "logIn"])->post("login/{provider:github|stack-exchange}", [$auth, "doLogInRedirect"])->get("login/{provider:github|stack-exchange}", [$auth, "doLogIn"])->get("join", [$auth, "join"])->post("join", [$auth, "doJoin"])->post("logout", [$auth, "doLogOut"]);
$router->get("ws", Aerys\websocket($injector->make("Kelunik\\ChatMain\\WebSocketChat")));
$root = root(realpath(__DIR__ . "/../public"), ["indexes" => []]);
$host = (new Aerys\Host())->expose("*", config("app.port"))->name(config("app.host"))->use($router)->use($root)->use(function (Request $request, Response $response) use($chat, $templateService) {
    $session = (yield (new Session($request))->read());
    $user = new User($session->get("login") ?? 0, $session->get("login:name") ?? "", $session->get("login:avatar") ?? "");
    $apiRequest = new StandardRequest("me/rooms", new stdClass(), null);
    $apiResponse = (yield $chat->process($apiRequest, $user));
    if ($apiResponse->getStatus() !== 200) {
        $response->setStatus(503);