1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license http://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yii\base; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Application is the base class for all application classes. |
14
|
|
|
* |
15
|
|
|
* For more details and usage information on Application, see the [guide article on applications](guide:structure-applications). |
16
|
|
|
* |
17
|
|
|
* @property \yii\web\AssetManager $assetManager The asset manager application component. This property is |
18
|
|
|
* read-only. |
19
|
|
|
* @property \yii\rbac\ManagerInterface $authManager The auth manager application component. Null is returned |
20
|
|
|
* if auth manager is not configured. This property is read-only. |
21
|
|
|
* @property string $basePath The root directory of the application. |
22
|
|
|
* @property \yii\caching\CacheInterface $cache The cache application component. Null if the component is not |
23
|
|
|
* enabled. This property is read-only. |
24
|
|
|
* @property array $container Values given in terms of name-value pairs. This property is write-only. |
25
|
|
|
* @property \yii\db\Connection $db The database connection. This property is read-only. |
26
|
|
|
* @property \yii\web\ErrorHandler|\yii\console\ErrorHandler $errorHandler The error handler application |
27
|
|
|
* component. This property is read-only. |
28
|
|
|
* @property \yii\i18n\Formatter $formatter The formatter application component. This property is read-only. |
29
|
|
|
* @property \yii\i18n\I18N $i18n The internationalization application component. This property is read-only. |
30
|
|
|
* @property \psr\log\LoggerInterface $logger The logger. |
31
|
|
|
* @property \yii\profile\ProfilerInterface $profiler The profiler. |
32
|
|
|
* @property \yii\mail\MailerInterface $mailer The mailer application component. This property is read-only. |
33
|
|
|
* @property \yii\web\Request|\yii\console\Request $request The request component. This property is read-only. |
34
|
|
|
* @property \yii\web\Response|\yii\console\Response $response The response component. This property is |
35
|
|
|
* read-only. |
36
|
|
|
* @property string $runtimePath The directory that stores runtime files. Defaults to the "runtime" |
37
|
|
|
* subdirectory under [[basePath]]. |
38
|
|
|
* @property \yii\base\Security $security The security application component. This property is read-only. |
39
|
|
|
* @property string $timeZone The time zone used by this application. |
40
|
|
|
* @property string $uniqueId The unique ID of the module. This property is read-only. |
41
|
|
|
* @property \yii\web\UrlManager $urlManager The URL manager for this application. This property is read-only. |
42
|
|
|
* @property string $vendorPath The directory that stores vendor files. Defaults to "vendor" directory under |
43
|
|
|
* [[basePath]]. |
44
|
|
|
* @property View|\yii\web\View $view The view application component that is used to render various view |
45
|
|
|
* files. This property is read-only. |
46
|
|
|
* |
47
|
|
|
* @author Qiang Xue <[email protected]> |
48
|
|
|
* @since 2.0 |
49
|
|
|
*/ |
50
|
|
|
abstract class Application extends Module |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* @event Event an event raised before the application starts to handle a request. |
54
|
|
|
*/ |
55
|
|
|
const EVENT_BEFORE_REQUEST = 'beforeRequest'; |
56
|
|
|
/** |
57
|
|
|
* @event Event an event raised after the application successfully handles a request (before the response is sent out). |
58
|
|
|
*/ |
59
|
|
|
const EVENT_AFTER_REQUEST = 'afterRequest'; |
60
|
|
|
/** |
61
|
|
|
* Application state used by [[state]]: application just started. |
62
|
|
|
*/ |
63
|
|
|
const STATE_BEGIN = 0; |
64
|
|
|
/** |
65
|
|
|
* Application state used by [[state]]: application is initializing. |
66
|
|
|
*/ |
67
|
|
|
const STATE_INIT = 1; |
68
|
|
|
/** |
69
|
|
|
* Application state used by [[state]]: application is triggering [[EVENT_BEFORE_REQUEST]]. |
70
|
|
|
*/ |
71
|
|
|
const STATE_BEFORE_REQUEST = 2; |
72
|
|
|
/** |
73
|
|
|
* Application state used by [[state]]: application is handling the request. |
74
|
|
|
*/ |
75
|
|
|
const STATE_HANDLING_REQUEST = 3; |
76
|
|
|
/** |
77
|
|
|
* Application state used by [[state]]: application is triggering [[EVENT_AFTER_REQUEST]].. |
78
|
|
|
*/ |
79
|
|
|
const STATE_AFTER_REQUEST = 4; |
80
|
|
|
/** |
81
|
|
|
* Application state used by [[state]]: application is about to send response. |
82
|
|
|
*/ |
83
|
|
|
const STATE_SENDING_RESPONSE = 5; |
84
|
|
|
/** |
85
|
|
|
* Application state used by [[state]]: application has ended. |
86
|
|
|
*/ |
87
|
|
|
const STATE_END = 6; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var string the namespace that controller classes are located in. |
91
|
|
|
* This namespace will be used to load controller classes by prepending it to the controller class name. |
92
|
|
|
* The default namespace is `app\controllers`. |
93
|
|
|
* |
94
|
|
|
* Please refer to the [guide about class autoloading](guide:concept-autoloading.md) for more details. |
95
|
|
|
*/ |
96
|
|
|
public $controllerNamespace = 'app\\controllers'; |
97
|
|
|
/** |
98
|
|
|
* @var string the application name. |
99
|
|
|
*/ |
100
|
|
|
public $name = 'My Application'; |
101
|
|
|
/** |
102
|
|
|
* @var string the charset currently used for the application. |
103
|
|
|
*/ |
104
|
|
|
public $charset = 'UTF-8'; |
105
|
|
|
/** |
106
|
|
|
* @var string the language that is meant to be used for end users. It is recommended that you |
107
|
|
|
* use [IETF language tags](http://en.wikipedia.org/wiki/IETF_language_tag). For example, `en` stands |
108
|
|
|
* for English, while `en-US` stands for English (United States). |
109
|
|
|
* @see sourceLanguage |
110
|
|
|
*/ |
111
|
|
|
public $language = 'en-US'; |
112
|
|
|
/** |
113
|
|
|
* @var string the language that the application is written in. This mainly refers to |
114
|
|
|
* the language that the messages and view files are written in. |
115
|
|
|
* @see language |
116
|
|
|
*/ |
117
|
|
|
public $sourceLanguage = 'en-US'; |
118
|
|
|
/** |
119
|
|
|
* @var Controller the currently active controller instance |
120
|
|
|
*/ |
121
|
|
|
public $controller; |
122
|
|
|
/** |
123
|
|
|
* @var string|bool the layout that should be applied for views in this application. Defaults to 'main'. |
124
|
|
|
* If this is false, layout will be disabled. |
125
|
|
|
*/ |
126
|
|
|
public $layout = 'main'; |
127
|
|
|
/** |
128
|
|
|
* @var string the requested route |
129
|
|
|
*/ |
130
|
|
|
public $requestedRoute; |
131
|
|
|
/** |
132
|
|
|
* @var Action the requested Action. If null, it means the request cannot be resolved into an action. |
133
|
|
|
*/ |
134
|
|
|
public $requestedAction; |
135
|
|
|
/** |
136
|
|
|
* @var array the parameters supplied to the requested action. |
137
|
|
|
*/ |
138
|
|
|
public $requestedParams; |
139
|
|
|
/** |
140
|
|
|
* @var array list of installed Yii extensions. Each array element represents a single extension |
141
|
|
|
* with the following structure: |
142
|
|
|
* |
143
|
|
|
* ```php |
144
|
|
|
* [ |
145
|
|
|
* 'name' => 'extension name', |
146
|
|
|
* 'version' => 'version number', |
147
|
|
|
* 'bootstrap' => 'BootstrapClassName', // optional, may also be a configuration array |
148
|
|
|
* 'alias' => [ |
149
|
|
|
* '@alias1' => 'to/path1', |
150
|
|
|
* '@alias2' => 'to/path2', |
151
|
|
|
* ], |
152
|
|
|
* ] |
153
|
|
|
* ``` |
154
|
|
|
* |
155
|
|
|
* The "bootstrap" class listed above will be instantiated during the application |
156
|
|
|
* [[bootstrap()|bootstrapping process]]. If the class implements [[BootstrapInterface]], |
157
|
|
|
* its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called. |
158
|
|
|
* |
159
|
|
|
* If not set explicitly in the application config, this property will be populated with the contents of |
160
|
|
|
* `@vendor/yiisoft/extensions.php`. |
161
|
|
|
*/ |
162
|
|
|
public $extensions; |
163
|
|
|
/** |
164
|
|
|
* @var array list of components that should be run during the application [[bootstrap()|bootstrapping process]]. |
165
|
|
|
* |
166
|
|
|
* Each component may be specified in one of the following formats: |
167
|
|
|
* |
168
|
|
|
* - an application component ID as specified via [[components]]. |
169
|
|
|
* - a module ID as specified via [[modules]]. |
170
|
|
|
* - a class name. |
171
|
|
|
* - a configuration array. |
172
|
|
|
* - a Closure |
173
|
|
|
* |
174
|
|
|
* During the bootstrapping process, each component will be instantiated. If the component class |
175
|
|
|
* implements [[BootstrapInterface]], its [[BootstrapInterface::bootstrap()|bootstrap()]] method |
176
|
|
|
* will be also be called. |
177
|
|
|
*/ |
178
|
|
|
public $bootstrap = []; |
179
|
|
|
/** |
180
|
|
|
* @var int the current application state during a request handling life cycle. |
181
|
|
|
* This property is managed by the application. Do not modify this property. |
182
|
|
|
*/ |
183
|
|
|
public $state; |
184
|
|
|
/** |
185
|
|
|
* @var array list of loaded modules indexed by their class names. |
186
|
|
|
*/ |
187
|
|
|
public $loadedModules = []; |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Constructor. |
192
|
|
|
* @param array $config name-value pairs that will be used to initialize the object properties. |
193
|
|
|
* Note that the configuration must contain both [[id]] and [[basePath]]. |
194
|
|
|
* @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing. |
195
|
|
|
*/ |
196
|
3184 |
|
public function __construct($config = []) |
197
|
|
|
{ |
198
|
3184 |
|
Yii::$app = $this; |
|
|
|
|
199
|
3184 |
|
static::setInstance($this); |
200
|
|
|
|
201
|
3184 |
|
$this->state = self::STATE_BEGIN; |
202
|
|
|
|
203
|
3184 |
|
$this->preInit($config); |
204
|
|
|
|
205
|
3184 |
|
$this->registerErrorHandler($config); |
206
|
|
|
|
207
|
3184 |
|
Component::__construct($config); |
208
|
3184 |
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Pre-initializes the application. |
212
|
|
|
* This method is called at the beginning of the application constructor. |
213
|
|
|
* It initializes several important application properties. |
214
|
|
|
* If you override this method, please make sure you call the parent implementation. |
215
|
|
|
* @param array $config the application configuration |
216
|
|
|
* @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing. |
217
|
|
|
*/ |
218
|
3184 |
|
public function preInit(&$config) |
219
|
|
|
{ |
220
|
3184 |
|
if (!isset($config['id'])) { |
221
|
|
|
throw new InvalidConfigException('The "id" configuration for the Application is required.'); |
222
|
|
|
} |
223
|
3184 |
|
if (isset($config['basePath'])) { |
224
|
3184 |
|
$this->setBasePath($config['basePath']); |
225
|
3184 |
|
unset($config['basePath']); |
226
|
|
|
} else { |
227
|
|
|
throw new InvalidConfigException('The "basePath" configuration for the Application is required.'); |
228
|
|
|
} |
229
|
|
|
|
230
|
3184 |
|
if (isset($config['vendorPath'])) { |
231
|
3178 |
|
$this->setVendorPath($config['vendorPath']); |
232
|
3178 |
|
unset($config['vendorPath']); |
233
|
|
|
} else { |
234
|
|
|
// set "@vendor" |
235
|
10 |
|
$this->getVendorPath(); |
236
|
|
|
} |
237
|
3184 |
|
if (isset($config['runtimePath'])) { |
238
|
|
|
$this->setRuntimePath($config['runtimePath']); |
239
|
|
|
unset($config['runtimePath']); |
240
|
|
|
} else { |
241
|
|
|
// set "@runtime" |
242
|
3184 |
|
$this->getRuntimePath(); |
243
|
|
|
} |
244
|
|
|
|
245
|
3184 |
|
if (isset($config['timeZone'])) { |
246
|
376 |
|
$this->setTimeZone($config['timeZone']); |
247
|
376 |
|
unset($config['timeZone']); |
248
|
2814 |
|
} elseif (!ini_get('date.timezone')) { |
249
|
|
|
$this->setTimeZone('UTC'); |
250
|
|
|
} |
251
|
|
|
|
252
|
3184 |
|
if (isset($config['container'])) { |
253
|
1 |
|
$this->setContainer($config['container']); |
254
|
1 |
|
unset($config['container']); |
255
|
|
|
} |
256
|
|
|
|
257
|
3184 |
|
if (isset($config['logger'])) { |
258
|
6 |
|
$this->setLogger($config['logger']); |
259
|
6 |
|
unset($config['logger']); |
260
|
|
|
} |
261
|
|
|
|
262
|
3184 |
|
if (isset($config['profiler'])) { |
263
|
|
|
$this->setProfiler($config['profiler']); |
264
|
|
|
unset($config['profiler']); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
// merge core components with custom components |
268
|
3184 |
|
foreach ($this->coreComponents() as $id => $component) { |
269
|
3184 |
|
if (!isset($config['components'][$id])) { |
270
|
3184 |
|
$config['components'][$id] = $component; |
271
|
430 |
|
} elseif (is_array($config['components'][$id]) && !isset($config['components'][$id]['class'])) { |
272
|
3184 |
|
$config['components'][$id]['class'] = $component['class']; |
273
|
|
|
} |
274
|
|
|
} |
275
|
3184 |
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* {@inheritdoc} |
279
|
|
|
*/ |
280
|
3184 |
|
public function init() |
281
|
|
|
{ |
282
|
3184 |
|
$this->state = self::STATE_INIT; |
283
|
3184 |
|
$this->bootstrap(); |
284
|
3184 |
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Initializes extensions and executes bootstrap components. |
288
|
|
|
* This method is called by [[init()]] after the application has been fully configured. |
289
|
|
|
* If you override this method, make sure you also call the parent implementation. |
290
|
|
|
*/ |
291
|
3184 |
|
protected function bootstrap() |
292
|
|
|
{ |
293
|
3184 |
|
if ($this->extensions === null) { |
294
|
3184 |
|
$file = Yii::getAlias('@vendor/yiisoft/extensions.php'); |
295
|
3184 |
|
$this->extensions = is_file($file) ? include $file : []; |
296
|
|
|
} |
297
|
3184 |
|
foreach ($this->extensions as $extension) { |
298
|
|
|
if (!empty($extension['alias'])) { |
299
|
|
|
foreach ($extension['alias'] as $name => $path) { |
300
|
|
|
Yii::setAlias($name, $path); |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
if (isset($extension['bootstrap'])) { |
304
|
|
|
$component = Yii::createObject($extension['bootstrap']); |
305
|
|
|
if ($component instanceof BootstrapInterface) { |
306
|
|
|
Yii::debug('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__); |
307
|
|
|
$component->bootstrap($this); |
308
|
|
|
} else { |
309
|
|
|
Yii::debug('Bootstrap with ' . get_class($component), __METHOD__); |
310
|
|
|
} |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|
314
|
3184 |
|
foreach ($this->bootstrap as $mixed) { |
315
|
2 |
|
$component = null; |
316
|
2 |
|
if ($mixed instanceof \Closure) { |
317
|
1 |
|
Yii::debug('Bootstrap with Closure', __METHOD__); |
318
|
1 |
|
if (!$component = call_user_func($mixed, $this)) { |
319
|
1 |
|
continue; |
320
|
|
|
} |
321
|
2 |
|
} elseif (is_string($mixed)) { |
322
|
2 |
|
if ($this->has($mixed)) { |
323
|
2 |
|
$component = $this->get($mixed); |
324
|
1 |
|
} elseif ($this->hasModule($mixed)) { |
325
|
1 |
|
$component = $this->getModule($mixed); |
326
|
|
|
} elseif (strpos($mixed, '\\') === false) { |
327
|
|
|
throw new InvalidConfigException("Unknown bootstrapping component ID: $mixed"); |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
|
331
|
2 |
|
if (!isset($component)) { |
332
|
|
|
$component = Yii::createObject($mixed); |
333
|
|
|
} |
334
|
|
|
|
335
|
2 |
|
if ($component instanceof BootstrapInterface) { |
336
|
1 |
|
Yii::debug('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__); |
337
|
1 |
|
$component->bootstrap($this); |
338
|
|
|
} else { |
339
|
2 |
|
Yii::debug('Bootstrap with ' . get_class($component), __METHOD__); |
340
|
|
|
} |
341
|
|
|
} |
342
|
3184 |
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Registers the errorHandler component as a PHP error handler. |
346
|
|
|
* @param array $config application config |
347
|
|
|
*/ |
348
|
3184 |
|
protected function registerErrorHandler(&$config) |
349
|
|
|
{ |
350
|
3184 |
|
if (YII_ENABLE_ERROR_HANDLER) { |
351
|
|
|
if (!isset($config['components']['errorHandler']['class'])) { |
352
|
|
|
echo "Error: no errorHandler component is configured.\n"; |
353
|
|
|
exit(1); |
354
|
|
|
} |
355
|
|
|
$this->set('errorHandler', $config['components']['errorHandler']); |
356
|
|
|
unset($config['components']['errorHandler']); |
357
|
|
|
$this->getErrorHandler()->register(); |
358
|
|
|
} |
359
|
3184 |
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* Returns an ID that uniquely identifies this module among all modules within the current application. |
363
|
|
|
* Since this is an application instance, it will always return an empty string. |
364
|
|
|
* @return string the unique ID of the module. |
365
|
|
|
*/ |
366
|
1 |
|
public function getUniqueId() |
367
|
|
|
{ |
368
|
1 |
|
return ''; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Sets the root directory of the application and the @app alias. |
373
|
|
|
* This method can only be invoked at the beginning of the constructor. |
374
|
|
|
* @param string $path the root directory of the application. |
375
|
|
|
* @property string the root directory of the application. |
376
|
|
|
* @throws InvalidArgumentException if the directory does not exist. |
377
|
|
|
*/ |
378
|
3184 |
|
public function setBasePath($path) |
379
|
|
|
{ |
380
|
3184 |
|
parent::setBasePath($path); |
381
|
3184 |
|
Yii::setAlias('@app', $this->getBasePath()); |
382
|
3184 |
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* Runs the application. |
386
|
|
|
* This is the main entrance of an application. |
387
|
|
|
* @return int the exit status (0 means normal, non-zero values mean abnormal) |
388
|
|
|
*/ |
389
|
|
|
public function run() |
390
|
|
|
{ |
391
|
|
|
try { |
392
|
|
|
$this->state = self::STATE_BEFORE_REQUEST; |
393
|
|
|
$this->trigger(self::EVENT_BEFORE_REQUEST); |
394
|
|
|
|
395
|
|
|
$this->state = self::STATE_HANDLING_REQUEST; |
396
|
|
|
$response = $this->handleRequest($this->getRequest()); |
397
|
|
|
|
398
|
|
|
$this->state = self::STATE_AFTER_REQUEST; |
399
|
|
|
$this->trigger(self::EVENT_AFTER_REQUEST); |
400
|
|
|
|
401
|
|
|
$this->state = self::STATE_SENDING_RESPONSE; |
402
|
|
|
$response->send(); |
403
|
|
|
|
404
|
|
|
$this->state = self::STATE_END; |
405
|
|
|
|
406
|
|
|
return $response->exitStatus; |
407
|
|
|
} catch (ExitException $e) { |
408
|
|
|
$this->end($e->statusCode, isset($response) ? $response : null); |
409
|
|
|
return $e->statusCode; |
410
|
|
|
} |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Handles the specified request. |
415
|
|
|
* |
416
|
|
|
* This method should return an instance of [[Response]] or its child class |
417
|
|
|
* which represents the handling result of the request. |
418
|
|
|
* |
419
|
|
|
* @param Request $request the request to be handled |
420
|
|
|
* @return Response the resulting response |
421
|
|
|
*/ |
422
|
|
|
abstract public function handleRequest($request); |
423
|
|
|
|
424
|
|
|
private $_runtimePath; |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Returns the directory that stores runtime files. |
428
|
|
|
* @return string the directory that stores runtime files. |
429
|
|
|
* Defaults to the "runtime" subdirectory under [[basePath]]. |
430
|
|
|
*/ |
431
|
3184 |
|
public function getRuntimePath() |
432
|
|
|
{ |
433
|
3184 |
|
if ($this->_runtimePath === null) { |
434
|
3184 |
|
$this->setRuntimePath($this->getBasePath() . DIRECTORY_SEPARATOR . 'runtime'); |
435
|
|
|
} |
436
|
|
|
|
437
|
3184 |
|
return $this->_runtimePath; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* Sets the directory that stores runtime files. |
442
|
|
|
* @param string $path the directory that stores runtime files. |
443
|
|
|
*/ |
444
|
3184 |
|
public function setRuntimePath($path) |
445
|
|
|
{ |
446
|
3184 |
|
$this->_runtimePath = Yii::getAlias($path); |
447
|
3184 |
|
Yii::setAlias('@runtime', $this->_runtimePath); |
448
|
3184 |
|
} |
449
|
|
|
|
450
|
|
|
private $_vendorPath; |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* Returns the directory that stores vendor files. |
454
|
|
|
* @return string the directory that stores vendor files. |
455
|
|
|
* Defaults to "vendor" directory under [[basePath]]. |
456
|
|
|
*/ |
457
|
10 |
|
public function getVendorPath() |
458
|
|
|
{ |
459
|
10 |
|
if ($this->_vendorPath === null) { |
460
|
10 |
|
$this->setVendorPath($this->getBasePath() . DIRECTORY_SEPARATOR . 'vendor'); |
461
|
|
|
} |
462
|
|
|
|
463
|
10 |
|
return $this->_vendorPath; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Sets the directory that stores vendor files. |
468
|
|
|
* @param string $path the directory that stores vendor files. |
469
|
|
|
*/ |
470
|
3184 |
|
public function setVendorPath($path) |
471
|
|
|
{ |
472
|
3184 |
|
$this->_vendorPath = Yii::getAlias($path); |
473
|
3184 |
|
Yii::setAlias('@vendor', $this->_vendorPath); |
474
|
3184 |
|
Yii::setAlias('@bower', $this->_vendorPath . DIRECTORY_SEPARATOR . 'bower'); |
475
|
3184 |
|
Yii::setAlias('@npm', $this->_vendorPath . DIRECTORY_SEPARATOR . 'npm'); |
476
|
3184 |
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Returns the time zone used by this application. |
480
|
|
|
* This is a simple wrapper of PHP function date_default_timezone_get(). |
481
|
|
|
* If time zone is not configured in php.ini or application config, |
482
|
|
|
* it will be set to UTC by default. |
483
|
|
|
* @return string the time zone used by this application. |
484
|
|
|
* @see http://php.net/manual/en/function.date-default-timezone-get.php |
485
|
|
|
*/ |
486
|
310 |
|
public function getTimeZone() |
487
|
|
|
{ |
488
|
310 |
|
return date_default_timezone_get(); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Sets the time zone used by this application. |
493
|
|
|
* This is a simple wrapper of PHP function date_default_timezone_set(). |
494
|
|
|
* Refer to the [php manual](http://www.php.net/manual/en/timezones.php) for available timezones. |
495
|
|
|
* @param string $value the time zone used by this application. |
496
|
|
|
* @see http://php.net/manual/en/function.date-default-timezone-set.php |
497
|
|
|
*/ |
498
|
376 |
|
public function setTimeZone($value) |
499
|
|
|
{ |
500
|
376 |
|
date_default_timezone_set($value); |
501
|
376 |
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* Returns the database connection component. |
505
|
|
|
* @return \yii\db\Connection the database connection. |
506
|
|
|
*/ |
507
|
85 |
|
public function getDb() |
508
|
|
|
{ |
509
|
85 |
|
return $this->get('db'); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Sets up or configure the logger instance. |
514
|
|
|
* @param \psr\log\LoggerInterface|\Closure|array|null $logger the logger object or its DI compatible configuration. |
515
|
|
|
* @since 2.1.0 |
516
|
|
|
*/ |
517
|
6 |
|
public function setLogger($logger) |
518
|
|
|
{ |
519
|
6 |
|
Yii::setLogger($logger); |
520
|
6 |
|
} |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* Returns the logger instance. |
524
|
|
|
* @return \psr\log\LoggerInterface the logger instance. |
525
|
|
|
* @since 2.1.0 |
526
|
|
|
*/ |
527
|
5 |
|
public function getLogger() |
528
|
|
|
{ |
529
|
5 |
|
return Yii::getLogger(); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* Sets up or configure the profiler instance. |
534
|
|
|
* @param \yii\profile\ProfilerInterface|\Closure|array|null $profiler the profiler object or its DI compatible configuration. |
535
|
|
|
* @since 2.1.0 |
536
|
|
|
*/ |
537
|
|
|
public function setProfiler($profiler) |
538
|
|
|
{ |
539
|
|
|
Yii::setProfiler($profiler); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* Returns the profiler instance. |
544
|
|
|
* @return \yii\profile\ProfilerInterface profiler instance. |
545
|
|
|
* @since 2.1.0 |
546
|
|
|
*/ |
547
|
|
|
public function getProfiler() |
548
|
|
|
{ |
549
|
|
|
return Yii::getProfiler(); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
/** |
553
|
|
|
* Returns the error handler component. |
554
|
|
|
* @return \yii\web\ErrorHandler|\yii\console\ErrorHandler the error handler application component. |
555
|
|
|
*/ |
556
|
|
|
public function getErrorHandler() |
557
|
|
|
{ |
558
|
|
|
return $this->get('errorHandler'); |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* Returns the cache component. |
563
|
|
|
* @return \yii\caching\CacheInterface the cache application component. Null if the component is not enabled. |
564
|
|
|
*/ |
565
|
|
|
public function getCache() |
566
|
|
|
{ |
567
|
|
|
return $this->get('cache', false); |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* Returns the formatter component. |
572
|
|
|
* @return \yii\i18n\Formatter the formatter application component. |
573
|
|
|
*/ |
574
|
31 |
|
public function getFormatter() |
575
|
|
|
{ |
576
|
31 |
|
return $this->get('formatter'); |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
/** |
580
|
|
|
* Returns the request component. |
581
|
|
|
* @return \yii\web\Request|\yii\console\Request the request component. |
582
|
|
|
*/ |
583
|
|
|
public function getRequest() |
584
|
|
|
{ |
585
|
|
|
return $this->get('request'); |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* Returns the response component. |
590
|
|
|
* @return \yii\web\Response|\yii\console\Response the response component. |
591
|
|
|
*/ |
592
|
|
|
public function getResponse() |
593
|
|
|
{ |
594
|
|
|
return $this->get('response'); |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* Returns the view object. |
599
|
|
|
* @return View|\yii\web\View the view application component that is used to render various view files. |
600
|
|
|
*/ |
601
|
46 |
|
public function getView() |
602
|
|
|
{ |
603
|
46 |
|
return $this->get('view'); |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* Returns the URL manager for this application. |
608
|
|
|
* @return \yii\web\UrlManager the URL manager for this application. |
609
|
|
|
*/ |
610
|
36 |
|
public function getUrlManager() |
611
|
|
|
{ |
612
|
36 |
|
return $this->get('urlManager'); |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* Returns the internationalization (i18n) component. |
617
|
|
|
* @return \yii\i18n\I18N the internationalization application component. |
618
|
|
|
*/ |
619
|
538 |
|
public function getI18n() |
620
|
|
|
{ |
621
|
538 |
|
return $this->get('i18n'); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
/** |
625
|
|
|
* Returns the mailer component. |
626
|
|
|
* @return \yii\mail\MailerInterface the mailer application component. |
627
|
|
|
*/ |
628
|
|
|
public function getMailer() |
629
|
|
|
{ |
630
|
|
|
return $this->get('mailer'); |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
/** |
634
|
|
|
* Returns the auth manager for this application. |
635
|
|
|
* @return \yii\rbac\ManagerInterface the auth manager application component. |
636
|
|
|
* Null is returned if auth manager is not configured. |
637
|
|
|
*/ |
638
|
|
|
public function getAuthManager() |
639
|
|
|
{ |
640
|
|
|
return $this->get('authManager', false); |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
/** |
644
|
|
|
* Returns the asset manager. |
645
|
|
|
* @return \yii\web\AssetManager the asset manager application component. |
646
|
|
|
*/ |
647
|
7 |
|
public function getAssetManager() |
648
|
|
|
{ |
649
|
7 |
|
return $this->get('assetManager'); |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
/** |
653
|
|
|
* Returns the security component. |
654
|
|
|
* @return \yii\base\Security the security application component. |
655
|
|
|
*/ |
656
|
56 |
|
public function getSecurity() |
657
|
|
|
{ |
658
|
56 |
|
return $this->get('security'); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
/** |
662
|
|
|
* Returns the configuration of core application components. |
663
|
|
|
* @see set() |
664
|
|
|
*/ |
665
|
3184 |
|
public function coreComponents() |
666
|
|
|
{ |
667
|
|
|
return [ |
668
|
3184 |
|
'security' => ['class' => Security::class], |
669
|
|
|
'formatter' => ['class' => \yii\i18n\Formatter::class], |
670
|
|
|
'i18n' => ['class' => \yii\i18n\I18N::class], |
671
|
|
|
'mailer' => ['class' => \yii\swiftmailer\Mailer::class], |
672
|
|
|
'assetManager' => ['class' => \yii\web\AssetManager::class], |
673
|
|
|
'urlManager' => ['class' => \yii\web\UrlManager::class], |
674
|
|
|
'view' => ['class' => \yii\web\View::class], |
675
|
|
|
]; |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
/** |
679
|
|
|
* Terminates the application. |
680
|
|
|
* This method replaces the `exit()` function by ensuring the application life cycle is completed |
681
|
|
|
* before terminating the application. |
682
|
|
|
* @param int $status the exit status (value 0 means normal exit while other values mean abnormal exit). |
683
|
|
|
* @param Response $response the response to be sent. If not set, the default application [[response]] component will be used. |
684
|
|
|
* @throws ExitException if the application is in testing mode |
685
|
|
|
*/ |
686
|
3 |
|
public function end($status = 0, $response = null) |
687
|
|
|
{ |
688
|
3 |
|
if ($this->state === self::STATE_BEFORE_REQUEST || $this->state === self::STATE_HANDLING_REQUEST) { |
689
|
|
|
$this->state = self::STATE_AFTER_REQUEST; |
690
|
|
|
$this->trigger(self::EVENT_AFTER_REQUEST); |
691
|
|
|
} |
692
|
|
|
|
693
|
3 |
|
if ($this->state !== self::STATE_SENDING_RESPONSE && $this->state !== self::STATE_END) { |
694
|
3 |
|
$this->state = self::STATE_END; |
695
|
3 |
|
$response = $response ?: $this->getResponse(); |
696
|
3 |
|
$response->send(); |
697
|
|
|
} |
698
|
|
|
|
699
|
3 |
|
if (YII_ENV_TEST) { |
700
|
3 |
|
throw new ExitException($status); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
exit($status); |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
/** |
707
|
|
|
* Configures [[Yii::$container]] with the $config. |
708
|
|
|
* |
709
|
|
|
* @param array $config values given in terms of name-value pairs |
710
|
|
|
* @since 2.0.11 |
711
|
|
|
*/ |
712
|
1 |
|
public function setContainer($config) |
713
|
|
|
{ |
714
|
1 |
|
Yii::configure(Yii::$container, $config); |
715
|
1 |
|
} |
716
|
|
|
} |
717
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..