-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathserver.php
More file actions
122 lines (109 loc) · 3.46 KB
/
server.php
File metadata and controls
122 lines (109 loc) · 3.46 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
declare(strict_types=1);
/**
* This file is a part of secure-php-login-system.
*
* @author Akbar Hashmi (Owner/Developer) <me@akbarhashmi.com>.
* @author Nicholas English (Collaborator/Developer) <nenglish0820@outlook.com>.
*
* @link <https://github.com/akbarhashmi/Secure-PHP-Login-System> Github repository.
* @license <https://github.com/akbarhashmi/Secure-PHP-Login-System/blob/master/LICENSE> MIT license.
*/
// Define the system root.
define('SYSTEM_ROOT', __DIR__);
// Check composer.
if (!file_exists(SYSTEM_ROOT . '/vendor/autoload.php')) {
trigger_error('You need to run composer install or else the system will not run.', E_USER_ERROR);
}
// Just in case require composer.
// Use require once so composer does not get loaded twice.
require_once SYSTEM_ROOT . '/vendor/autoload.php';
// Load the Engine\App configuration.
require_once SYSTEM_ROOT . '/load.php';
// Start pimple.
$container = new Pimple\Container();
// Inject the configuration.
$container['config'] = $config;
// Create a database connection.
$container['db'] = function ($c)
{
if ($c['config']['db']['driver'] == 'mysql')
{
// Start a MySQL connection.
return new Akbarhashmi\Engine\Database\MySQLConnect(
$c['config']['db']['hostname'],
$c['config']['db']['port'],
$c['config']['db']['database'],
$c['config']['db']['username'],
$c['config']['db']['password'],
$c['config']['db']['debug']
);
} elseif ($c['config']['db']['driver'] == 'pgsql')
{
// Start a PgSQL connection.
return new Akbarhashmi\Engine\Database\PostgreSQLConnect(
$c['config']['db']['hostname'],
$c['config']['db']['port'],
$c['config']['db']['database'],
$c['config']['db']['username'],
$c['config']['db']['password'],
$c['config']['db']['debug']
);
} else
{
// Kill the script if an invalid driver is passed.
die('Database driver is not supported.');
}
};
// Inject the cookie handler.
$container['cookie'] = $container->factory(function ($c)
{
return new Akbarhashmi\Engine\Cookie($c['config']);
});
// Inject the session handler.
$container['session'] = $container->factory(function ($c)
{
return new Akbarhashmi\Engine\Session\Session($c['config']);
});
// Inject the language switcher.
$container['lang'] = $container->factory(function ($c)
{
return new Akbarhashmi\Engine\Lang(
$c['config'],
$c['session'],
$c['cookie']
);
});
// Check to see if the secure session should be auto started.
if ((bool) $container['config']['session']['auto_start'] === true)
{
// Start a secure session.
$container['session']->start();
}
// Set the language if requested.
if (isset($_GET['lang']))
{
// Set the new language.
$container['lang']->setLanguage($_GET['lang']);
}
// Our container management.
Akbarhashmi\Engine\Container::setContainer($container);
function engine($service = null)
{
// Check the service data type
if (!is_null($service) && !is_string($service))
{
// Return null.
return null;
}
// Get the container instance.
$container = Akbarhashmi\Engine\Container::getInstance();
// Check to see if a service is passed.
if (is_null($service))
{
// Return the engine pimple container.
return $container;
}
// Return the service.
return $container[(string) $service];
}