1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Executes a target file of a request |
5
|
|
|
* |
6
|
|
|
* PHP Version 5 |
7
|
|
|
* |
8
|
|
|
* @category Core |
9
|
|
|
* @package Router |
10
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
11
|
|
|
* @copyright 2013 cSphere Team |
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
13
|
|
|
* @link http://www.csphere.eu |
14
|
|
|
**/ |
15
|
|
|
|
16
|
|
|
namespace csphere\core\router; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Executes a target file of a request |
20
|
|
|
* |
21
|
|
|
* @category Core |
22
|
|
|
* @package Router |
23
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
24
|
|
|
* @copyright 2013 cSphere Team |
25
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
26
|
|
|
* @link http://www.csphere.eu |
27
|
|
|
**/ |
28
|
|
|
|
29
|
|
|
class Sandbox |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Include a target file and control error handling |
33
|
|
|
* |
34
|
|
|
* @param string $file File name with full path |
35
|
|
|
* |
36
|
|
|
* @return boolean |
37
|
|
|
**/ |
|
|
|
|
38
|
|
|
|
39
|
|
|
public static function full($file) |
40
|
|
|
{ |
41
|
|
|
// Use output buffer to not get verbose |
42
|
|
|
ob_start(); |
43
|
|
|
|
44
|
|
|
// Try to include and execute the target file |
45
|
|
|
try { |
46
|
|
|
|
47
|
|
|
include $file; |
48
|
|
|
|
49
|
|
|
} catch (\Exception $exception) { |
50
|
|
|
|
51
|
|
|
$controller = new \csphere\core\errors\Controller($exception, true); |
52
|
|
|
|
53
|
|
|
unset($controller); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
ob_end_clean(); |
57
|
|
|
|
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Include a target file without error handling |
63
|
|
|
* |
64
|
|
|
* @param string $file File name with full path |
65
|
|
|
* |
66
|
|
|
* @return boolean |
67
|
|
|
**/ |
|
|
|
|
68
|
|
|
|
69
|
|
|
public static function light($file) |
70
|
|
|
{ |
71
|
|
|
// Use output buffer to not get verbose |
72
|
|
|
ob_start(); |
73
|
|
|
|
74
|
|
|
// Hide error messages at this part |
75
|
|
|
$errors = ini_get('display_errors'); |
76
|
|
|
ini_set('display_errors', 0); |
77
|
|
|
|
78
|
|
|
include $file; |
79
|
|
|
|
80
|
|
|
// Change error messages back to default setting |
81
|
|
|
ini_set('display_errors', $errors); |
82
|
|
|
|
83
|
|
|
ob_end_clean(); |
84
|
|
|
|
85
|
|
|
return true; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|