forked from chenjundong/fraym
/
Bootstrap.php
executable file
·85 lines (66 loc) · 2.56 KB
/
Bootstrap.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
<?php
/**
* @link http://fraym.org
* @author Dominik Weber <info@fraym.org>
* @copyright Dominik Weber <info@fraym.org>
* @license http://www.opensource.org/licenses/gpl-license.php GNU General Public License, version 2 or later (see the LICENSE file)
*/
chdir(realpath(dirname(__FILE__)));
require 'Vendor/DI/functions.php';
require 'Fraym/ClassLoader/ClassLoader.php';
$classLoader = new Fraym\ClassLoader\ClassLoader();
$classLoader->register();
if (is_file('Config.php')) {
require 'Config.php';
} else {
header('HTTP/1.1 500 Internal Server Error');
echo '<a href="/install.php">Please install Fraym.</a>';
exit(0);
}
date_default_timezone_set(TIMEZONE);
$diContainer = new \DI\ContainerBuilder();
define('APC_ENABLED', extension_loaded('apc') && ini_get('apc.enabled'));
if (\Fraym\Core::ENV_STAGING === ENV || \Fraym\Core::ENV_PRODUCTION === ENV) {
error_reporting(0);
ini_set("display_errors", 0);
if (!is_dir('Cache/DI')) {
mkdir('Cache/DI', 0755);
}
$builder = new \DI\ContainerBuilder();
if (APC_ENABLED) {
$cache = new Doctrine\Common\Cache\ApcCache();
} else {
$cache = new Doctrine\Common\Cache\ArrayCache();
}
$cache->setNamespace('Fraym_instance_' . FRAYM_INSTANCE);
$builder->setDefinitionCache($cache);
$builder->writeProxiesToFile(true, 'Cache/DI');
$diContainer = $builder->build();
define('GLOBAL_CACHING_ENABLED', true);
} else {
error_reporting(-1);
ini_set("display_errors", 1);
$builder = new \DI\ContainerBuilder();
if (APC_ENABLED && \Fraym\Core::ENV_TESTING === ENV) {
$cache = new Doctrine\Common\Cache\ApcCache();
} else {
$cache = new Doctrine\Common\Cache\ArrayCache();
}
$builder->setDefinitionCache($cache);
$diContainer = $builder->build();
define('GLOBAL_CACHING_ENABLED', false);
}
$diContainer->set('db.options', array('driver' => DB_DRIVER,
'user' => DB_USER,
'password' => DB_PASS,
'host' => DB_HOST,
'dbname' => DB_NAME,
'charset' => DB_CHARSET,
));
if (defined('IMAGE_PROCESSOR') && IMAGE_PROCESSOR === 'Imagick') {
$diContainer->set('Imagine', DI\link('Imagine\Imagick\Imagine'));
} elseif (defined('IMAGE_PROCESSOR') && IMAGE_PROCESSOR === 'Gmagick') {
$diContainer->set('Imagine', DI\link('Imagine\Gmagick\Imagine'));
} else {
$diContainer->set('Imagine', DI\link('Imagine\Gd\Imagine'));
}