1 <?php
2
3 if (!defined('GEN_START')) {
4 http_response_code(404);
5 } else {
6
7 /**
8 * The global framework class
9 *
10 * @author Art <a.molcanovas@gmail.com>
11 */
12 class Alo {
13
14 /**
15 * SFTP connection manager
16 *
17 * @var Alo\SFTP
18 */
19 static $sftp;
20
21 /**
22 * Code profiler
23 *
24 * @var Alo\Profiler
25 */
26 static $profiler;
27
28 /**
29 * File manager
30 *
31 * @var Alo\FileSystem\File
32 */
33 static $file;
34
35 /**
36 * Email manager
37 *
38 * @var Alo\Email
39 */
40 static $email;
41
42 /**
43 * Object-oriented Curl wrapper
44 *
45 * @var Alo\Curl
46 */
47 static $curl;
48
49 /**
50 * Crontab manager
51 *
52 * @var Alo\Cron
53 */
54 static $cron;
55
56 /**
57 * HTML form validator
58 *
59 * @var Alo\Validators\Form
60 */
61 static $formValidator;
62
63 /**
64 * Database connection
65 *
66 * @var Alo\Db\AbstractDb
67 */
68 static $db;
69
70 /**
71 * Cache instance
72 *
73 * @var Alo\Cache\AbstractCache
74 */
75 static $cache;
76
77 /**
78 * The loaded controller
79 *
80 * @var Alo\Controller\AbstractController
81 */
82 static $controller;
83
84 /**
85 * The routing class
86 *
87 * @var Alo\Controller\Router
88 */
89 static $router;
90
91 /**
92 * Windows service handler
93 *
94 * @var Alo\Windows\Service
95 */
96 static $service;
97
98 /**
99 * Download manager
100 *
101 * @var Alo\CLI\Downloader
102 */
103 static $downloader;
104
105 /**
106 * Locale manager
107 *
108 * @var Alo\Locale
109 */
110 static $locale;
111
112 /**
113 * Loads a configuration file based on environment: from DIR_SYS/config during setup & DIR_APP/config during
114 * production/development
115 *
116 * @author Art <a.molcanovas@gmail.com>
117 *
118 * @param string $path The config file relative path without the file extension, e.g. to load a file found
119 * in config/db/mysql.php provide db/mysql
120 * @param bool $returnPath If set to true it will return the calculated path instead of requiring the file
121 *
122 * @return string|bool The path is $returnPath is true, TRUE if it is false
123 */
124 static function loadConfig($path, $returnPath = false) {
125 $dir = (defined('ENVIRONMENT') && ENVIRONMENT === ENV_SETUP ? DIR_SYS : DIR_APP) . 'config' .
126 DIRECTORY_SEPARATOR;
127 $path = strtolower($path);
128 if (substr($path, -4) == '.php') {
129 $path = substr($path, 0, -4);
130 }
131
132 /** @noinspection PhpUnusedLocalVariableInspection */
133 $finalPath = '';
134 if (file_exists($dir . $path . '.php')) {
135 $finalPath = $dir . $path . '.php';
136 } else {
137 trigger_error('Configuration file ' . $path .
138 ' not found in the application folder. Attempting to load from sys.', E_USER_WARNING);
139 $finalPath = DIR_SYS . 'config' . DIRECTORY_SEPARATOR . $path . '.php';
140 }
141
142 if ($returnPath) {
143 return $finalPath;
144 } else {
145 include_once $finalPath;
146
147 return true;
148 }
149 }
150
151 /**
152 * Performs include() only if a file exists
153 *
154 * @param string $path Path to the file
155 *
156 * @return bool true if the file exists, false if not.
157 */
158 static function includeifexists($path) {
159 if (file_exists($path)) {
160 include $path;
161
162 return true;
163 }
164
165 return false;
166 }
167
168 /**
169 * Performs include_once() only if a file exists
170 *
171 * @param string $path Path to the file
172 *
173 * @return bool true if the file exists, false if not.
174 */
175 static function includeonceifexists($path) {
176 if (file_exists($path)) {
177 include_once $path;
178
179 return true;
180 }
181
182 return false;
183 }
184
185 /**
186 * Check if the server is running Windows
187 *
188 * @author Art <a.molcanovas@gmail.com>
189 * @return bool
190 */
191 static function serverIsWindows() {
192 return substr(strtoupper(php_uname('s')), 0, 3) === 'WIN';
193 }
194 }
195
196 \Log::debug('Alo framework class initialised');
197 }
198