-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
112 lines (102 loc) · 2.4 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Load the composer autoload file
*/
$autoloader = require 'vendor/autoload.php';
/**
* Initialize the Slim App
*
* Initializing a Slim App and setting the default settings
*/
$app = new \Slim\App(["settings" => require(__DIR__ . "/settings.php")]);
/**
* Our view handler
*
* @param array $files
* @param array $args
*
* @return Object
*/
$app->getContainer()["view"] = function() use($app) {
return new class($app) {
private $scope;
public function __construct($app) {
$this->scope = $app;
}
public function render($files, array $args = []){
$files = (array) $files;
$app = $this->scope;
$cb = (function() use($files, $args, $app) {
ob_start();
extract($args);
foreach ( $files as $file ) {
$orig = $file;
$file = $file = __DIR__ . "/" . "views" . "/" . $file;
if ( is_file($file) ) {
require $file;
} else if ( is_file($file = $file . ".php") ) {
require $file;
} else if ( is_file($file = $file . ".html") ) {
require $file;
} else {
throw new Exception("View (" + $orig + ") not found !");
}
}
return $app->getContainer()->response->getBody()->write(ob_get_clean());
});
return ($cb->bindTo($app->getContainer()))();
}
};
};
/**
* Our autoload handler
*
* @return Composer\Autoload\ClassLoader
*/
$app->getContainer()["autoloader"] = function() use($autoloader) {
return $autoloader;
};
/**
* Prepare capsule "laravel database manager"
*/
use Illuminate\Database\Capsule\Manager as Capsule;
{
/**
* Initialize capsule
*
* @return Illuminate\Database\Capsule\Manager
*/
$capsule = new Illuminate\Database\Capsule\Manager;
/**
* Set this instance as global
*/
$capsule->setAsGlobal();
/**
* Makes capsule available via $app
*
* @return Illuminate\Database\Capsule\Manager
*/
$app->getContainer()["capsule"] = function() use($capsule) {
return $capsule;
};
/**
* Adding connections to capsule
*/
foreach ( (array) $app->getContainer()->settings["capsule"] as $name => $conn ) {
$capsule->addConnection($conn, $name);
}
}
/**
* Loading routes
*
* load all available routes in routes directory
*/
foreach ( glob(__DIR__ . "/" . "routes" . "/" . "*.php") as $route ) {
require_once $route;
}
/**
* Dispatch !
*
* Run the whole app now !
*/
$app->run();