-
Notifications
You must be signed in to change notification settings - Fork 94
/
app.php
executable file
·55 lines (43 loc) · 1.81 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
use Silex\Application;
use Silex\Provider\HttpCacheServiceProvider;
use Silex\Provider\DoctrineServiceProvider;
use Silex\Provider\MonologServiceProvider;
use Silex\Provider\ServiceControllerServiceProvider;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use App\ServicesLoader;
use App\RoutesLoader;
use Carbon\Carbon;
date_default_timezone_set('Europe/London');
//accepting JSON
$app->before(function (Request $request) {
if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
$data = json_decode($request->getContent(), true);
$request->request->replace(is_array($data) ? $data : array());
}
});
$app->register(new \Euskadi31\Silex\Provider\CorsServiceProvider);
$app->register(new ServiceControllerServiceProvider());
$app->register(new DoctrineServiceProvider(), array(
"db.options" => $app["db.options"]
));
$app->register(new HttpCacheServiceProvider(), array("http_cache.cache_dir" => ROOT_PATH . "/storage/cache",));
$app->register(new MonologServiceProvider(), array(
"monolog.logfile" => ROOT_PATH . "/storage/logs/" . Carbon::now('Europe/London')->format("Y-m-d") . ".log",
"monolog.level" => $app["log.level"],
"monolog.name" => "application"
));
//load services
$servicesLoader = new App\ServicesLoader($app);
$servicesLoader->bindServicesIntoContainer();
//load routes
$routesLoader = new App\RoutesLoader($app);
$routesLoader->bindRoutesToControllers();
$app->error(function (\Exception $e, $code) use ($app) {
$app['monolog']->addError($e->getMessage());
$app['monolog']->addError($e->getTraceAsString());
return new JsonResponse(array("statusCode" => $code, "message" => $e->getMessage(), "stacktrace" => $e->getTraceAsString()));
});
return $app;