index.php 1.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<?php
if (PHP_SAPI == 'cli-server') {
    // To help the built-in PHP dev server, check if the request was actually for
    // something which should probably be served as a static file
    $url = parse_url($_SERVER['REQUEST_URI']);
    $file = __DIR__ . $url['path'];
    if (is_file($file)) {
        return false;
    }
}

$autoloader = require __DIR__ . '/../vendor/autoload.php';

session_name('MineduOsteamApp');
session_start();

date_default_timezone_set('Europe/Athens');

// Instantiate the app
$settings_file = __DIR__ . '/../src/settings.php';
if (is_readable($settings_file)) {
    $settings = require($settings_file);
} else {
    $settings = [];
}
$app = new \Slim\App($settings);
$container = $app->getContainer();

// Set up dependencies
require __DIR__ . '/../src/dependencies.php';

//
// setup the app 
//
$container['autoloader'] = $autoloader;
$autoloader->addPsr4('Gr\Gov\Minedu\Osteam\Slim\\', __DIR__ . '/../src/osteam');
$container['errorHandler'] = function ($c) {
    return function ($request, $response, $exception) use ($c) {
        return $c['response']->withJson([
40 41 42
                'success' => false,
                'timestamp' => date('c'),
                'message' => 'An error occured',
43 44 45 46 47 48 49 50 51 52 53 54 55 56
                'in' => $exception->getMessage()
                ], intval($code = $exception->getCode()) > 0 ? $code : null
        );
    };
};

// Register routes
require __DIR__ . '/../src/routes.php';

// Register middleware
require __DIR__ . '/../src/middleware.php';

// Run app
$app->run();