Exemple #1
0
    $logger->message(sprintf('[%s] : Started dbCharts', date(DATE_ATOM)));
    // --- Request
    $logger->message("Creating request...", true);
    $request = Request::fromGlobals();
    $logger->done();
    $logger->message('Handling request ' . "`{$request->getMethod()} {$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}`");
    // --- PDO configuration
    $pdo_cfg_path = '/../app/pdo.cfg';
    $logger->message("Loading PDO configuration from file '" . $pdo_cfg_path . "'...", true);
    $pdo_config = new FilePDOBuilder(__DIR__ . $pdo_cfg_path);
    $logger->done();
    // --- Controller
    $logger->message("Creating controller...", true);
    $controller = new \DS3\Application\Controller($pdo_config, $logger);
    $logger->done();
    // --- Response
    $logger->message("Creating response...", true);
    try {
        $response = $controller->handle($request);
    } catch (\Exception $e) {
        throw new \Exception("Cannot handle request", 0, $e);
    }
    $logger->done();
    $logger->message("Sending response", false);
    $response->send();
} catch (\Exception $e) {
    $json = JsonHandler::encode($e);
    $logger->message($e);
    $response = new JsonResponse($json, 500);
    $response->send();
}
Exemple #2
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use DS3\Framework\HTTP\Request;
use DS3\Framework\PDO\FilePDOBuilder;
use DS3\Framework\HTTP\JsonResponse;
use DS3\Framework\Logger\Logger;
use DS3\Framework\Filesystem\File;
use DS3\Framework\HTTP\JsonHandler;
$logger = new Logger(new File(__DIR__ . '/../app/prod.log'));
$logger->message(sprintf('[%s] : Started dbCharts', date(DATE_ATOM)), true);
try {
    $request = Request::fromGlobals();
    $pdo_config = new FilePDOBuilder(__DIR__ . '/../app/pdo.cfg');
    $controller = new \DS3\Application\Controller($pdo_config, $logger);
    $response = $controller->handle($request);
    $response->send();
    $logger->done();
} catch (\Exception $e) {
    $logger->message(sprintf('Exception occured : %s', JsonHandler::encode($e)));
    $response = new JsonResponse(array('code' => 500, 'message' => 'Internal Server Error'), 500);
    $response->send();
    $logger->done();
}