You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

58 lines
1.4 KiB

<?php
require_once(__DIR__.'/../vendor/autoload.php');
use Etu\Controller\Inventory as InventoryController;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
$app = new Slim\App();
/**
* Set up routes
*/
$app->get('/inventory/{item}', function (Request $request, Response $response, array $args) {
return $this[InventoryController::class]->get($request, $response, $args);
});
/**
* Set up dependencies
*/
$container = $app->getContainer();
$container['logger'] = function (Slim\Container $c) {
$logger = new \Monolog\Logger('inventory-logger');
$logger->pushProcessor(new \Monolog\Processor\PsrLogMessageProcessor());
return $logger;
};
$container['db'] = function (Slim\Container $c) {
$pdo = new PDO('sqlite:../sqlite.db');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$pdo->exec(
'DROP TABLE IF EXISTS inventory;'
);
$pdo->exec(
'CREATE TABLE inventory (
item_id INTEGER PRIMARY KEY,
item_name TEXT NOT NULL,
item_stock INTEGER NOT NULL
);'
);
return $pdo;
};
/**
* Set up controllers
*/
$container[InventoryController::class] = function (Slim\Container $c) {
return new InventoryController($c['logger']);
};
$app->run();