-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.php
36 lines (28 loc) · 906 Bytes
/
app.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
<?php
/**
* Silex application
* @author: Nikolay Ermin <[email protected]>
*/
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
require_once __DIR__.'/vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = false;
$database = __DIR__ . '/database.json';
$app->get('/', function(){
return file_get_contents(__DIR__ . '/index.html');
});
// Save basket
$app->post('/basket', function( Request $request ) use ( $database ) {
file_put_contents( $database, $request->getContent() );
return new JsonResponse(['message' => 'Save successfully']);
});
// Load basket
$app->get('/basket', function() use ( $database ) {
$data = file_exists( $database )
? json_decode(file_get_contents( $database ), true)
: [];
return new JsonResponse($data);
});
$app->run();