-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.php
59 lines (47 loc) · 1.09 KB
/
helpers.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
<?php
/**
* Basic autoload function
*
* @param string $file
*/
spl_autoload_register(function ($file) {
$filepath = __DIR__ . '/src/' . $file . '.php';
if (is_readable($filepath)) {
require $filepath;
}
});
/**
* Try connect to database
*
* @param string $name Connection name or alias
*
* @return PDO Instance of PDO class
*
* @throws PDOException If cannot connect
*/
if (! function_exists('get_connection')) {
function get_connection($name = 'default') {
try {
return new PDO('mysql:dbname=eit;host=127.0.0.1', 'root', '');
} catch (PDOException $e) {
throw new Exception($e->getMessage(), 1);
}
}
}
/**
* Get the full name for the view
*
* @param string $name
*
* @return string
*/
if (! function_exists('view')) {
function view($name, $data = []) {
$path = 'views/' . $name . '.php';
if (! is_readable($path)) {
throw new Exception('The view file does not exists or is not readable.');
}
extract($data);
require $path;
}
}