This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
66 lines (46 loc) · 1.49 KB
/
bootstrap.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
56
57
58
59
60
61
62
63
64
65
66
<?php
// Create Application Instance
include __DIR__ . '/vendor/autoload.php';
use Config\Config;
use Silex\Application;
$app = new Application();
// Exception Handler
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
error_reporting(-1);
ErrorHandler::register();
ExceptionHandler::register();
// Environment
define('APPROOT', __DIR__);
$app['version'] = '0.0.0';
$app['env'] = getenv('APP_ENV') ?: 'development';
$app['debug'] = $app['env'] === 'development' ? true : false;
// Configuration
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . '/app/Config/' . $app['env'] . '.php'));
// Connect to MongoDB and apply MinifySchema
$app->register(new MongoMinify\Silex\ServiceProvider());
// Register Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__ . '/app/View',
'twig.options' => array(
'cache' => __DIR__ . '/cache'
)
));
// Logging
$app->register(new Silex\Provider\MonologServiceProvider(), array(
'monolog.name' => 'SilexMongoSkeleton',
'monolog.level' => Monolog\Logger::WARNING,
'monolog.logfile' => __DIR__ . '/logs/' . date('Y-m-d') . '-' . $app['env'] . '.log',
));
// Custom Error Handler
$app->error(function ($exception, $code) use ($app) {
if ($code === 404)
{
return 'Error 404: Not Found';
}
});
// App Routes
$app->get('/', Router::getController('Index'));
$app->get('/example-json', Router::getController('JsonExample'));
// Return Instance
return $app;