-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
98 lines (74 loc) · 2.79 KB
/
bootstrap.php
File metadata and controls
98 lines (74 loc) · 2.79 KB
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
<?php
use Cradle\Logger;
use DI\Container;
use Slim\Factory\AppFactory;
use Cradle\ViewCompiler;
use Psr\Container\ContainerInterface;
/**
* ------------------------------------------------------------------
* Cradle
* ------------------------------------------------------------------
*
* Cradle is an MVC microframework for building web apps with PHP.
*
* It is made with the aim to help php developers avoid working with spaghetti code
* and embrace the MVC software architecture in as little time as possible.
* It is totally free to use and open source.
*
* @package Cradle
* @version 1.0
* @author Mohammed Adekunle (Iyiola) <adekunle3317@gmail.com>
*/
// Ensure the server is running the minimum allowed PHP version.
// Current minimum: 7.2
if (version_compare(PHP_VERSION, '7.2', '<')) {
http_response_code(503);
echo "<b>Error:</b> Cradle requires a minimum PHP version of 7.2 to run.<br/><b>Current PHP version:</b> PHP_VERSION";
exit(1);
}
// Define file structure.
define('BASE_DIR', __DIR__); // Define the base directory
define('PUBLIC_DIR', BASE_DIR . '/public'); // Define the public directory
define('RESOURCES_DIR', BASE_DIR . '/resources'); // Define resources directory
define('STORAGE_DIR', BASE_DIR . '/storage'); // Define the storage directory
// Include the composer autoloader.
require_once BASE_DIR . '/vendor/autoload.php';
// Load environment values from the .env file if a .env file exists.
if (file_exists(BASE_DIR . '/.env')) {
\Dotenv\Dotenv::createImmutable(BASE_DIR)->load();
}
// Set up error handling based on app environment configuration
switch (getenv('APP_ENVIRONMENT')) { // Configure the exceptions and error logging levels based on the environment configuration
case 'development': // All errors and exceptions are reported in development mode
error_reporting(E_ALL);
ini_set('DISPLAY_ERRORS', 'stdout');
define('SHOW_ERRORS', true);
break;
case 'maintenance': // Site maintenance mode
// Fall through
case 'production': // No errors and exceptions are reported in production mode
error_reporting(0);
ini_set('DISPLAY_ERRORS', 'stderr');
define('SHOW_ERRORS', false);
break;
default: // In case the environment was incorrectly set
http_response_code(503);
echo '<b>Error:</b> The application environment is not set correctly.';
exit(1);
break;
}
// Create a dependency container.
// All your container bindings should be defined here.
$container = new Container();
// Add the view compiler object.
$container->set('view', function (ContainerInterface $container) {
return new ViewCompiler();
});
// Add the logger object.
$container->set('logger', function (ContainerInterface $container) {
return new Logger();
});
// Create a new slim app.
$app = AppFactory::createFromContainer($container);
// Return the new app instance
return $app;