Ejemplo n.º 1
0
<?php

use Bravicility\Failure\FailureHandler;
use FileSystem\Dearchiver;
use FileSystem\Directory;
use DataSource\XmlReader;
require_once __DIR__ . '/../vendor/autoload.php';
$container = new Container();
$db = $container->getDb();
$logger = $container->getErrorLogger();
FailureHandler::setup(function ($error) use($logger) {
    $logger->error($error['message'], $error);
    fwrite(STDERR, "В процессе инициализации произошла ошибка:\n{$error['message']}\n");
    exit(1);
});
$db->start();
if ($_SERVER['argc'] == 2) {
    $path = $_SERVER['argv']['1'];
    if (!is_dir($path)) {
        $path = Dearchiver::extract($container->getFileDirectory(), $path);
    }
    $directory = new Directory($path);
} else {
    $loader = $container->getUpdateLoader();
    $directory = $loader->load();
}
$oldVersionId = UpdateLogHelper::getLastVersionId($db);
$newVersionId = $directory->getVersionId();
if ($newVersionId != $oldVersionId + 1) {
    throw new \LogicException("Попытка обновления с версии {$oldVersionId} на версию {$newVersionId}.");
}
Ejemplo n.º 2
0
<?php

use Bravicility\Failure\FailureHandler;
use Bravicility\Http\Request;
use Bravicility\Http\Response\Response;
use Bravicility\Http\Response\TextResponse;
use Bravicility\Router\RouteNotFoundException;
require_once __DIR__ . '/../vendor/autoload.php';
$container = new Container();
$logger = $container->getErrorLogger();
FailureHandler::setup(function ($error) use($logger) {
    (new TextResponse(500, 'Произошла ошибка сервера'))->send();
    $logger->error($error['message'], $error);
    exit;
});
try {
    $request = Request::createFromGlobals();
    $route = $container->getRouter()->route($request->getMethod(), $request->getUrlPath());
    $request->setOptions($route->vars);
    /** @var Response $response */
    $response = (new $route->class($container))->{$route->method}($request);
} catch (RouteNotFoundException $e) {
    $response = new Response(404);
} catch (BadRequestException $e) {
    $response = new Response(400, $e->getMessage());
}
$response->addHeader('Access-Control-Allow-Origin: *');
$response->send();