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.
 
 

60 lines
1.5 KiB

<?php
require_once(__DIR__.'/../vendor/autoload.php');
use Etu\Controller\Inventory as InventoryController;
use Etu\Helpers\Inventory as InventoryHelper;
use Monolog\Logger;
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::class] = function (Slim\Container $c) {
$logger = new \Monolog\Logger('inventory-logger');
$logger->pushProcessor(new \Monolog\Processor\PsrLogMessageProcessor());
return $logger;
};
$container[PDO::class] = 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(
'CREATE TABLE IF NOT EXISTS inventory (
item_id INTEGER PRIMARY KEY,
item_name TEXT NOT NULL,
item_stock INTEGER NOT NULL
);'
);
return $pdo;
};
$container[InventoryHelper::class] = function (Slim\Container $c) {
return new InventoryHelper($c[PDO::class]);
};
/**
* Set up controllers
*/
$container[InventoryController::class] = function (Slim\Container $c) {
return new InventoryController($c[Logger::class], $c[InventoryHelper::class]);
};
$app->run();