1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Alxarafe. Development of PHP applications in a flash! |
4
|
|
|
* Copyright (C) 2018 Alxarafe <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Alxarafe\Core\Base; |
8
|
|
|
|
9
|
|
|
use Alxarafe\Database\Engine; |
10
|
|
|
use Alxarafe\Database\SqlHelper; |
11
|
|
|
use DebugBar\DebugBarException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Controller |
15
|
|
|
* |
16
|
|
|
* The controller is who responds to the various events. |
17
|
|
|
* |
18
|
|
|
* @package Alxarafe\Core\Base |
19
|
|
|
*/ |
20
|
|
|
abstract class Controller extends BasicController |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The database engine. |
24
|
|
|
* |
25
|
|
|
* @var Engine |
26
|
|
|
*/ |
27
|
|
|
public static Engine $engine; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The database SQL Helper. |
31
|
|
|
* |
32
|
|
|
* @var SqlHelper |
33
|
|
|
*/ |
34
|
|
|
public static SqlHelper $sqlHelper; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* It contains an instance of the view class, or null if it is |
38
|
|
|
* not assigned, or does not have an associated view. |
39
|
|
|
* |
40
|
|
|
* @var View |
41
|
|
|
*/ |
42
|
|
|
public View $view; |
43
|
|
|
|
44
|
|
|
public function __construct() |
45
|
|
|
{ |
46
|
|
|
parent::__construct(); |
47
|
|
|
|
48
|
|
|
$this->hasMenu = true; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Initialization of variables required for all controllers |
53
|
|
|
* |
54
|
|
|
* @return bool |
55
|
|
|
* @throws DebugBarException |
56
|
|
|
*/ |
57
|
|
|
public function preLoad(): bool |
58
|
|
|
{ |
59
|
|
|
if (!parent::preLoad() || !$this->configExists) { |
60
|
|
|
die('No existe el archivo de configuración!'); // No tendría que haber llegado aquí, pero sin configuración, no se puede utilizar base de datos. |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (!$this->config->connectToDatabaseAndAuth()) { |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
self::$engine = $this->config->getEngine(); |
68
|
|
|
self::$sqlHelper = $this->config->getSqlHelper(); |
69
|
|
|
|
70
|
|
|
$this->action = filter_input(INPUT_POST, 'action', FILTER_DEFAULT); |
71
|
|
|
|
72
|
|
|
// TODO: This will have to be assigned in a yaml file, when activating and deactivating modules. |
73
|
|
|
$this->translator->addDirs([ |
74
|
|
|
constant('BASE_FOLDER') . '/Modules/Main', |
75
|
|
|
]); |
76
|
|
|
|
77
|
|
|
return true; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.