-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
91 lines (75 loc) · 2.14 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use DI\Container as DIContainer;
use Piksi\Helpers\UrlManager;
use Piksi\Controllers\ExceptionController;
use Psr\Container\ContainerInterface as Container;
use Slim\Factory\AppFactory;
use Slim\Views\Blade;
// Check base requirements
require_once __DIR__ . '/helpers/RequirementsChecker.php';
$requirementsChecker = new Piksi\Helpers\RequirementsChecker();
try
{
$requirementsChecker->CheckEnvironment();
}
catch (\Exception $ex)
{
exit('Unable to run Piksi: ' . $ex->getMessage());
}
// Load composer dependencies
require_once __DIR__ . '/packages/autoload.php';
// Load config files
require_once PIKSI_DATAPATH . '/config.php';
require_once __DIR__ . '/config-dist.php'; // For not in own config defined values we use the default ones
// Check required config options
try
{
$requirementsChecker->CheckConfig();
}
catch (\Exception $ex)
{
exit('Unable to run Piksi (config.php check failed): ' . $ex->getMessage());
}
// Error reporting definitions
if (PIKSI_MODE === 'dev')
{
error_reporting(E_ALL);
}
else
{
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING | E_DEPRECATED));
}
// Create data/viewcache folder if it doesn't exist
if (!file_exists(PIKSI_DATAPATH . '/viewcache'))
{
mkdir(PIKSI_DATAPATH . '/viewcache');
}
// Setup base application
AppFactory::setContainer(new DIContainer());
$app = AppFactory::create();
$container = $app->getContainer();
$container->set('view', function (Container $container)
{
return new Blade(__DIR__ . '/views', PIKSI_DATAPATH . '/viewcache');
});
$container->set('UrlManager', function (Container $container)
{
return new UrlManager(PIKSI_BASE_URL);
});
// Load routes from separate file
require_once __DIR__ . '/routes.php';
// Set base path if defined
if (!empty(PIKSI_BASE_PATH))
{
$app->setBasePath(PIKSI_BASE_PATH);
}
define('PIKSI_LOCALE', PIKSI_LOCALE);
// Add default middleware
$app->addRoutingMiddleware();
$errorMiddleware = $app->addErrorMiddleware(true, false, false);
$errorMiddleware->setDefaultErrorHandler(
new ExceptionController($app, $container)
);
$app->getRouteCollector()->setCacheFile(PIKSI_DATAPATH . '/viewcache/route_cache.php');
ob_clean(); // No response output before here
$app->run();