Example #1
0
// $app = new \Slim\App($c);
$app = new \Slim\App();
// define the $app's package dependencies inside containers ////////////////////
$container = $app->getContainer();
// Twig is to render basic html, it has other uses but we have no choice to use
// a rendering engine with Slim ////////////////////////////////////////////////
$container['view'] = function ($container) {
    $view = new \Slim\Views\Twig($_SERVER['DOCUMENT_ROOT'] . '/src/client/', ['cache' => false]);
    $view->addExtension(new \Slim\Views\TwigExtension($container['router'], $container['request']->getUri()));
    return $view;
};
// duncan3dc\SqlClass\Sql is a data/abstraction layer class for interfacing ////
// with our db: why reinvent the wheel? ////////////////////////////////////////
$container['sql'] = function ($container) {
    duncan3dc\SqlClass\Sql::addServer('le-huard', ['mode' => getenv('MODE'), 'hostname' => getenv('HOSTNAME'), 'username' => getenv('USERNAME'), 'password' => getenv('PASSWORD'), 'database' => getenv('DB')]);
    $sql = duncan3dc\SqlClass\Sql::getInstance('le-huard');
    return $sql;
};
/////////////// end app config and container declaration //////////////////////
/////////////////////////////////// ROUTES /////////////////////////////////////
// when accessing the root of the website we should return the angul app at ////
// index.html and let it handle its own routes /////////////////////////////////
$app->get('/', function ($request, $response, $args) {
    // serve the angular app ///////////////////////////////////////////////////
    return $this->view->render($response, '/app/index.html');
});
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// API ///////////////////////////////////////////
// API routes should either return json data based on the Database or a header
// status code
//