forked from phalcon/cphalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.zep
141 lines (120 loc) · 2.86 KB
/
application.zep
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalconphp.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon;
use Phalcon\Application\Exception;
use Phalcon\DiInterface;
use Phalcon\Di\Injectable;
use Phalcon\Events\EventsAwareInterface;
use Phalcon\Events\ManagerInterface;
/**
* Phalcon\Application
*
* Base class for Phalcon\Cli\Console and Phalcon\Mvc\Application.
*/
abstract class Application extends Injectable implements EventsAwareInterface
{
protected _eventsManager;
protected _dependencyInjector;
/**
* @var string
*/
protected _defaultModule;
/**
* @var array
*/
protected _modules = [];
/**
* Phalcon\Application
*/
public function __construct(<DiInterface> dependencyInjector = null)
{
if typeof dependencyInjector == "object" {
let this->_dependencyInjector = dependencyInjector;
}
}
/**
* Sets the events manager
*/
public function setEventsManager(<ManagerInterface> eventsManager) -> <Application>
{
let this->_eventsManager = eventsManager;
return this;
}
/**
* Returns the internal event manager
*/
public function getEventsManager() -> <ManagerInterface>
{
return this->_eventsManager;
}
/**
* Register an array of modules present in the application
*
* <code>
* $this->registerModules(
* [
* "frontend" => [
* "className" => "Multiple\\Frontend\\Module",
* "path" => "../apps/frontend/Module.php",
* ],
* "backend" => [
* "className" => "Multiple\\Backend\\Module",
* "path" => "../apps/backend/Module.php",
* ],
* ]
* );
* </code>
*/
public function registerModules(array modules, bool merge = false) -> <Application>
{
if merge {
let this->_modules = array_merge(this->_modules, modules);
} else {
let this->_modules = modules;
}
return this;
}
/**
* Return the modules registered in the application
*/
public function getModules() -> array
{
return this->_modules;
}
/**
* Gets the module definition registered in the application via module name
*/
public function getModule(string! name) -> array | object
{
var module;
if !fetch module, this->_modules[name] {
throw new Exception("Module '" . name . "' isn't registered in the application container");
}
return module;
}
/**
* Sets the module name to be used if the router doesn't return a valid module
*/
public function setDefaultModule(string! defaultModule) -> <Application>
{
let this->_defaultModule = defaultModule;
return this;
}
/**
* Returns the default module name
*/
public function getDefaultModule() -> string
{
return this->_defaultModule;
}
/**
* Handles a request
*/
abstract public function handle();
}