/
start-cron.php
executable file
·51 lines (37 loc) · 1.38 KB
/
start-cron.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
<?php
namespace Hawk;
/*** Initialize the application ***/
define('SCRIPT_START_TIME', microtime(true));
define('ROOT_DIR', __DIR__ . '/');
define('INCLUDES_DIR', ROOT_DIR . 'includes/');
// Get the core constants
require INCLUDES_DIR . 'constants.php';
// Get the constants customized by developer for the application
if(!is_file(INCLUDES_DIR . 'custom-constants.php')) {
touch(INCLUDES_DIR . 'custom-constants.php');
}
require INCLUDES_DIR . 'custom-constants.php';
// Load the autoload system
require INCLUDES_DIR . 'autoload.php';
$app = App::getInstance();
$app->isCron = true;
$app->init();
$app->on('after.route', function ($event) use($app) {
$req = $app->request;
$route = $req->route;
if(!$app->conf->has('db') && $route->getName() === 'index') {
// The application is not installed yet
$app->logger->notice('Hawk is not installed yet, redirect to install process page');
$app->response->redirectToRoute('install');
return;
}
elseif($app->conf->has('db') && in_array($route->getName(), array('install', 'install-settings'))) {
$app->response->redirectToRoute('index');
return;
}
});
$app->logger->debug('Script has been initialized');
$app->addMiddleware(new \Hawk\Middlewares\Configuration)
->addMiddleware(new \Hawk\Middlewares\StartPlugins)
->addMiddleware(new \Hawk\Middlewares\ExecuteCron);
$app->run();