-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
53 lines (39 loc) · 1.23 KB
/
index.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require 'vendor/autoload.php';
include 'middleware.php';
include 'functions.php';
// Create container
$container = new \Slim\Container;
// Register component on container
$container['view'] = function ($c) {
$view = new \Slim\Views\Twig('templates', [
'cache' => false
]);
$view->addExtension(new \Slim\Views\TwigExtension(
$c['router'],
$c['request']->getUri()
));
return $view;
};
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'API_KEY'])->notEmpty();
$app = new \Slim\App($container);
$app->post('/api/v1/theme', function ($request, $response, $args) {
$result = insert_theme_data($request->getParsedBody());
$response->write(json_encode(array(
'error' => false,
'message' => 'OK'
)));
//Override existing header with new header.
$response = $response->withHeader('Content-type', 'application/json');
return $response;
})->add($valid)->add($auth); // Middleware
// Render Twig template in route
$app->get('/', function ($request, $response, $args) {
$data = get_theme_data();
return $this->view->render($response, 'theme-data.html', [
'data' => $data
]);
})->setName('theme-data'); // Do I need setName?
$app->run();