-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCacaoFw.php
109 lines (87 loc) · 2.14 KB
/
CacaoFw.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace CacaoFw;
use CacaoFw\Security\AccessControl;
use CacaoFw\Service\DataService;
use CacaoFw\Service\LocalisationService;
use CacaoFw\Service\RouterService;
use CacaoFw\Service\RequestProcessorService;
/**
*
* @author Bence
*
*/
class CacaoFw {
/**
*
* @var array Application config file
*/
public $config;
/**
*
* @var Utils
*/
public $u;
/**
*
* @var User
*/
public $currentUser;
/**
*
* @var CacaoFw\Security\AccessControl;
*/
public $accessControl;
/**
*
* @var RouterService
*/
private $routerService;
public function __construct(\CacaoFw\Utils $u) {
global $DS, $CFW, $LANG;
$this->u = $u;
$this->setUpConfig();
$LANG = LocalisationService::init($this->config);
// Prepare data access.
$DS = DataService::init($this->config);
// prepare security
$this->accessControl = AccessControl::init();
$this->routerService = RouterService::init();
$CFW = $this;
RequestProcessorService::init($this->accessControl, $this->routerService)->processRequest();
}
/**
*
* @param array $file
* @param string $prefix
*/
public function saveFile($file, $prefix, $path) {
global $u;
if (! $file['error']) {
$name = uniqid($prefix) . '.' . end((explode(".", $file["name"])));
$newPath = realpath($u->getAppDir() . $path) . "/" . $name;
$result = move_uploaded_file($file['tmp_name'], $newPath);
if (! $result) {
throw new Exception("Failed to save file.");
}
return $name;
} else {
return null;
}
}
/**
* Load config file.
*/
private function setUpConfig() {
$this->config = parse_ini_file(__DIR__ . '/../app/config.ini');
}
/**
*
* @return User
*/
public function getCurrentUser() {
return $this->accessControl->currentUser;
}
public function isUserLoggedIn() {
return ! ! $this->accessControl->currentUser;
}
}