-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
72 lines (54 loc) · 1.97 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
// Get the config file
$config = require(__DIR__ . "/application/configs/config.development.php");
// Define a path to application directory
defined("APPLICATION_PATH") || define("APPLICATION_PATH", realpath($config['application']['location']));
// Include autoload
require __DIR__ . "/vendor/autoload.php";
// Create Container
$container = new \DI\Container();
\Slim\Factory\AppFactory::setContainer($container);
// Create the app
$app = \Slim\Factory\AppFactory::create();
// Define basepath if it's not defined on config
if(!isset($config['application']['basepath'])) {
$config['application']['basepath'] = str_replace($_SERVER['DOCUMENT_ROOT'], "", dirname($_SERVER['SCRIPT_NAME']));
if($config['application']['basepath'] == "/") {
$config['application']['basepath'] = "";
}
}
$app->setBasePath($config['application']['basepath']);
// Set view in Container
$container->set("view", function($container) use ($config) {
// Create smarty view
$view = new \Slim\Views\Smarty($config['smarty']);
// Return view object
return $view;
});
// Initialize database
if($config['db']['enabled']) {
$database = new \Illuminate\Database\Capsule\Manager();
$database->addConnection($config['db']);
$database->setAsGlobal();
$database->bootEloquent();
}
// Set the config
$container->set("config", function($container) use ($config) {
return $config;
});
// Routes
$routes = require(APPLICATION_PATH . "/configs/routes.php");
$container->set("routes", $routes);
foreach($routes as $name => $route) {
$app->map($route['type'], $route['pattern'], function (\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, $args) use ($config) {
// Call MVC bootstrap
$bootstrap = new \Application\Mvc\Bootstrap($this, $request, $response, $args, $config);
// Get response from controller
return $bootstrap->getResponse();
})
->setName($name);
}
// Run
$app->run();