GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f9fd4d...f5c98f )
by Robert
11:43
created

Application   C

Complexity

Total Complexity 70

Size/Duplication

Total Lines 628
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 69.59%

Importance

Changes 0
Metric Value
wmc 70
lcom 2
cbo 7
dl 0
loc 628
ccs 119
cts 171
cp 0.6959
rs 5.4597
c 0
b 0
f 0

32 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
C preInit() 0 49 12
A init() 0 5 1
D bootstrap() 0 52 17
A registerErrorHandler() 0 12 3
A setBasePath() 0 5 1
A run() 0 23 3
handleRequest() 0 1 ?
A getRuntimePath() 0 8 2
A setRuntimePath() 0 5 1
A getVendorPath() 0 8 2
A setVendorPath() 0 7 1
A getTimeZone() 0 4 1
A setTimeZone() 0 4 1
A getDb() 0 4 1
A getLog() 0 4 1
A getErrorHandler() 0 4 1
A getCache() 0 4 1
A getFormatter() 0 4 1
A getRequest() 0 4 1
A getResponse() 0 4 1
A getView() 0 4 1
A getUrlManager() 0 4 1
A getI18n() 0 4 1
A getMailer() 0 4 1
A getAuthManager() 0 4 1
A getAssetManager() 0 4 1
A getSecurity() 0 4 1
A coreComponents() 0 13 1
B end() 0 19 7
A setContainer() 0 4 1
A getUniqueId() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like Application often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Application, and based on these observations, apply Extract Interface, too.

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 enabled.
23
 * 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 \yii\log\Dispatcher $log The log dispatcher application component. This property is read-only.
31
 * @property \yii\mail\MailerInterface $mailer The mailer application component. This property is read-only.
32
 * @property \yii\web\Request|\yii\console\Request $request The request component. This property is read-only.
33
 * @property \yii\web\Response|\yii\console\Response $response The response component. This property is
34
 * read-only.
35
 * @property string $runtimePath The directory that stores runtime files. Defaults to the "runtime"
36
 * subdirectory under [[basePath]].
37
 * @property \yii\base\Security $security The security application component. This property is read-only.
38
 * @property string $timeZone The time zone used by this application.
39
 * @property string $uniqueId The unique ID of the module. This property is read-only.
40
 * @property \yii\web\UrlManager $urlManager The URL manager for this application. This property is read-only.
41
 * @property string $vendorPath The directory that stores vendor files. Defaults to "vendor" directory under
42
 * [[basePath]].
43
 * @property View|\yii\web\View $view The view application component that is used to render various view
44
 * files. This property is read-only.
45
 *
46
 * @author Qiang Xue <[email protected]>
47
 * @since 2.0
48
 */
49
abstract class Application extends Module
50
{
51
    /**
52
     * @event Event an event raised before the application starts to handle a request.
53
     */
54
    const EVENT_BEFORE_REQUEST = 'beforeRequest';
55
    /**
56
     * @event Event an event raised after the application successfully handles a request (before the response is sent out).
57
     */
58
    const EVENT_AFTER_REQUEST = 'afterRequest';
59
    /**
60
     * Application state used by [[state]]: application just started.
61
     */
62
    const STATE_BEGIN = 0;
63
    /**
64
     * Application state used by [[state]]: application is initializing.
65
     */
66
    const STATE_INIT = 1;
67
    /**
68
     * Application state used by [[state]]: application is triggering [[EVENT_BEFORE_REQUEST]].
69
     */
70
    const STATE_BEFORE_REQUEST = 2;
71
    /**
72
     * Application state used by [[state]]: application is handling the request.
73
     */
74
    const STATE_HANDLING_REQUEST = 3;
75
    /**
76
     * Application state used by [[state]]: application is triggering [[EVENT_AFTER_REQUEST]]..
77
     */
78
    const STATE_AFTER_REQUEST = 4;
79
    /**
80
     * Application state used by [[state]]: application is about to send response.
81
     */
82
    const STATE_SENDING_RESPONSE = 5;
83
    /**
84
     * Application state used by [[state]]: application has ended.
85
     */
86
    const STATE_END = 6;
87
88
    /**
89
     * @var string the namespace that controller classes are located in.
90
     * This namespace will be used to load controller classes by prepending it to the controller class name.
91
     * The default namespace is `app\controllers`.
92
     *
93
     * Please refer to the [guide about class autoloading](guide:concept-autoloading.md) for more details.
94
     */
95
    public $controllerNamespace = 'app\\controllers';
96
    /**
97
     * @var string the application name.
98
     */
99
    public $name = 'My Application';
100
    /**
101
     * @var string the charset currently used for the application.
102
     */
103
    public $charset = 'UTF-8';
104
    /**
105
     * @var string the language that is meant to be used for end users. It is recommended that you
106
     * use [IETF language tags](http://en.wikipedia.org/wiki/IETF_language_tag). For example, `en` stands
107
     * for English, while `en-US` stands for English (United States).
108
     * @see sourceLanguage
109
     */
110
    public $language = 'en-US';
111
    /**
112
     * @var string the language that the application is written in. This mainly refers to
113
     * the language that the messages and view files are written in.
114
     * @see language
115
     */
116
    public $sourceLanguage = 'en-US';
117
    /**
118
     * @var Controller the currently active controller instance
119
     */
120
    public $controller;
121
    /**
122
     * @var string|bool the layout that should be applied for views in this application. Defaults to 'main'.
123
     * If this is false, layout will be disabled.
124
     */
125
    public $layout = 'main';
126
    /**
127
     * @var string the requested route
128
     */
129
    public $requestedRoute;
130
    /**
131
     * @var Action the requested Action. If null, it means the request cannot be resolved into an action.
132
     */
133
    public $requestedAction;
134
    /**
135
     * @var array the parameters supplied to the requested action.
136
     */
137
    public $requestedParams;
138
    /**
139
     * @var array list of installed Yii extensions. Each array element represents a single extension
140
     * with the following structure:
141
     *
142
     * ```php
143
     * [
144
     *     'name' => 'extension name',
145
     *     'version' => 'version number',
146
     *     'bootstrap' => 'BootstrapClassName',  // optional, may also be a configuration array
147
     *     'alias' => [
148
     *         '@alias1' => 'to/path1',
149
     *         '@alias2' => 'to/path2',
150
     *     ],
151
     * ]
152
     * ```
153
     *
154
     * The "bootstrap" class listed above will be instantiated during the application
155
     * [[bootstrap()|bootstrapping process]]. If the class implements [[BootstrapInterface]],
156
     * its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called.
157
     *
158
     * If not set explicitly in the application config, this property will be populated with the contents of
159
     * `@vendor/yiisoft/extensions.php`.
160
     */
161
    public $extensions;
162
    /**
163
     * @var array list of components that should be run during the application [[bootstrap()|bootstrapping process]].
164
     *
165
     * Each component may be specified in one of the following formats:
166
     *
167
     * - an application component ID as specified via [[components]].
168
     * - a module ID as specified via [[modules]].
169
     * - a class name.
170
     * - a configuration array.
171
     * - a Closure
172
     *
173
     * During the bootstrapping process, each component will be instantiated. If the component class
174
     * implements [[BootstrapInterface]], its [[BootstrapInterface::bootstrap()|bootstrap()]] method
175
     * will be also be called.
176
     */
177
    public $bootstrap = [];
178
    /**
179
     * @var int the current application state during a request handling life cycle.
180
     * This property is managed by the application. Do not modify this property.
181
     */
182
    public $state;
183
    /**
184
     * @var array list of loaded modules indexed by their class names.
185
     */
186
    public $loadedModules = [];
187
188
189
    /**
190
     * Constructor.
191
     * @param array $config name-value pairs that will be used to initialize the object properties.
192
     * Note that the configuration must contain both [[id]] and [[basePath]].
193
     * @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing.
194
     */
195 2775
    public function __construct($config = [])
196
    {
197 2775
        Yii::$app = $this;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this of type this<yii\base\Application> is incompatible with the declared type object<yii\console\Appli...ct<yii\web\Application> of property $app.

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..

Loading history...
198 2775
        static::setInstance($this);
199
200 2775
        $this->state = self::STATE_BEGIN;
201
202 2775
        $this->preInit($config);
203
204 2775
        $this->registerErrorHandler($config);
205
206 2775
        Component::__construct($config);
207 2775
    }
208
209
    /**
210
     * Pre-initializes the application.
211
     * This method is called at the beginning of the application constructor.
212
     * It initializes several important application properties.
213
     * If you override this method, please make sure you call the parent implementation.
214
     * @param array $config the application configuration
215
     * @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing.
216
     */
217 2775
    public function preInit(&$config)
218
    {
219 2775
        if (!isset($config['id'])) {
220
            throw new InvalidConfigException('The "id" configuration for the Application is required.');
221
        }
222 2775
        if (isset($config['basePath'])) {
223 2775
            $this->setBasePath($config['basePath']);
224 2775
            unset($config['basePath']);
225
        } else {
226
            throw new InvalidConfigException('The "basePath" configuration for the Application is required.');
227
        }
228
229 2775
        if (isset($config['vendorPath'])) {
230 2769
            $this->setVendorPath($config['vendorPath']);
231 2769
            unset($config['vendorPath']);
232
        } else {
233
            // set "@vendor"
234 10
            $this->getVendorPath();
235
        }
236 2775
        if (isset($config['runtimePath'])) {
237
            $this->setRuntimePath($config['runtimePath']);
238
            unset($config['runtimePath']);
239
        } else {
240
            // set "@runtime"
241 2775
            $this->getRuntimePath();
242
        }
243
244 2775
        if (isset($config['timeZone'])) {
245 372
            $this->setTimeZone($config['timeZone']);
246 372
            unset($config['timeZone']);
247 2409
        } elseif (!ini_get('date.timezone')) {
248
            $this->setTimeZone('UTC');
249
        }
250
251 2775
        if (isset($config['container'])) {
252 1
            $this->setContainer($config['container']);
253
254 1
            unset($config['container']);
255
        }
256
257
        // merge core components with custom components
258 2775
        foreach ($this->coreComponents() as $id => $component) {
259 2775
            if (!isset($config['components'][$id])) {
260 2775
                $config['components'][$id] = $component;
261 406
            } elseif (is_array($config['components'][$id]) && !isset($config['components'][$id]['class'])) {
262 2775
                $config['components'][$id]['class'] = $component['class'];
263
            }
264
        }
265 2775
    }
266
267
    /**
268
     * @inheritdoc
269
     */
270 2775
    public function init()
271
    {
272 2775
        $this->state = self::STATE_INIT;
273 2775
        $this->bootstrap();
274 2775
    }
275
276
    /**
277
     * Initializes extensions and executes bootstrap components.
278
     * This method is called by [[init()]] after the application has been fully configured.
279
     * If you override this method, make sure you also call the parent implementation.
280
     */
281 2775
    protected function bootstrap()
282
    {
283 2775
        if ($this->extensions === null) {
284 2775
            $file = Yii::getAlias('@vendor/yiisoft/extensions.php');
285 2775
            $this->extensions = is_file($file) ? include $file : [];
286
        }
287 2775
        foreach ($this->extensions as $extension) {
288
            if (!empty($extension['alias'])) {
289
                foreach ($extension['alias'] as $name => $path) {
290
                    Yii::setAlias($name, $path);
291
                }
292
            }
293
            if (isset($extension['bootstrap'])) {
294
                $component = Yii::createObject($extension['bootstrap']);
295
                if ($component instanceof BootstrapInterface) {
296
                    Yii::trace('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__);
297
                    $component->bootstrap($this);
298
                } else {
299
                    Yii::trace('Bootstrap with ' . get_class($component), __METHOD__);
300
                }
301
            }
302
        }
303
304 2775
        foreach ($this->bootstrap as $mixed) {
305 2
            $component = null;
306 2
            if ($mixed instanceof \Closure) {
307 1
                Yii::trace('Bootstrap with Closure', __METHOD__);
308 1
                if (!$component = call_user_func($mixed, $this)) {
309 1
                    continue;
310
                }
311 2
            } elseif (is_string($mixed)) {
312 2
                if ($this->has($mixed)) {
313 2
                    $component = $this->get($mixed);
314 1
                } elseif ($this->hasModule($mixed)) {
315 1
                    $component = $this->getModule($mixed);
316
                } elseif (strpos($mixed, '\\') === false) {
317
                    throw new InvalidConfigException("Unknown bootstrapping component ID: $mixed");
318
                }
319
            }
320
321 2
            if (!isset($component)) {
322
                $component = Yii::createObject($mixed);
323
            }
324
325 2
            if ($component instanceof BootstrapInterface) {
326 1
                Yii::trace('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__);
327 1
                $component->bootstrap($this);
328
            } else {
329 2
                Yii::trace('Bootstrap with ' . get_class($component), __METHOD__);
330
            }
331
        }
332 2775
    }
333
334
    /**
335
     * Registers the errorHandler component as a PHP error handler.
336
     * @param array $config application config
337
     */
338 2775
    protected function registerErrorHandler(&$config)
339
    {
340 2775
        if (YII_ENABLE_ERROR_HANDLER) {
341
            if (!isset($config['components']['errorHandler']['class'])) {
342
                echo "Error: no errorHandler component is configured.\n";
343
                exit(1);
344
            }
345
            $this->set('errorHandler', $config['components']['errorHandler']);
346
            unset($config['components']['errorHandler']);
347
            $this->getErrorHandler()->register();
348
        }
349 2775
    }
350
351
    /**
352
     * Returns an ID that uniquely identifies this module among all modules within the current application.
353
     * Since this is an application instance, it will always return an empty string.
354
     * @return string the unique ID of the module.
355
     */
356 1
    public function getUniqueId()
357
    {
358 1
        return '';
359
    }
360
361
    /**
362
     * Sets the root directory of the application and the @app alias.
363
     * This method can only be invoked at the beginning of the constructor.
364
     * @param string $path the root directory of the application.
365
     * @property string the root directory of the application.
366
     * @throws InvalidParamException if the directory does not exist.
367
     */
368 2775
    public function setBasePath($path)
369
    {
370 2775
        parent::setBasePath($path);
371 2775
        Yii::setAlias('@app', $this->getBasePath());
372 2775
    }
373
374
    /**
375
     * Runs the application.
376
     * This is the main entrance of an application.
377
     * @return int the exit status (0 means normal, non-zero values mean abnormal)
378
     */
379
    public function run()
380
    {
381
        try {
382
            $this->state = self::STATE_BEFORE_REQUEST;
383
            $this->trigger(self::EVENT_BEFORE_REQUEST);
384
385
            $this->state = self::STATE_HANDLING_REQUEST;
386
            $response = $this->handleRequest($this->getRequest());
387
388
            $this->state = self::STATE_AFTER_REQUEST;
389
            $this->trigger(self::EVENT_AFTER_REQUEST);
390
391
            $this->state = self::STATE_SENDING_RESPONSE;
392
            $response->send();
393
394
            $this->state = self::STATE_END;
395
396
            return $response->exitStatus;
397
        } catch (ExitException $e) {
398
            $this->end($e->statusCode, isset($response) ? $response : null);
399
            return $e->statusCode;
400
        }
401
    }
402
403
    /**
404
     * Handles the specified request.
405
     *
406
     * This method should return an instance of [[Response]] or its child class
407
     * which represents the handling result of the request.
408
     *
409
     * @param Request $request the request to be handled
410
     * @return Response the resulting response
411
     */
412
    abstract public function handleRequest($request);
413
414
    private $_runtimePath;
415
416
    /**
417
     * Returns the directory that stores runtime files.
418
     * @return string the directory that stores runtime files.
419
     * Defaults to the "runtime" subdirectory under [[basePath]].
420
     */
421 2775
    public function getRuntimePath()
422
    {
423 2775
        if ($this->_runtimePath === null) {
424 2775
            $this->setRuntimePath($this->getBasePath() . DIRECTORY_SEPARATOR . 'runtime');
425
        }
426
427 2775
        return $this->_runtimePath;
428
    }
429
430
    /**
431
     * Sets the directory that stores runtime files.
432
     * @param string $path the directory that stores runtime files.
433
     */
434 2775
    public function setRuntimePath($path)
435
    {
436 2775
        $this->_runtimePath = Yii::getAlias($path);
437 2775
        Yii::setAlias('@runtime', $this->_runtimePath);
0 ignored issues
show
Bug introduced by
It seems like $this->_runtimePath can also be of type boolean; however, yii\BaseYii::setAlias() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
438 2775
    }
439
440
    private $_vendorPath;
441
442
    /**
443
     * Returns the directory that stores vendor files.
444
     * @return string the directory that stores vendor files.
445
     * Defaults to "vendor" directory under [[basePath]].
446
     */
447 10
    public function getVendorPath()
448
    {
449 10
        if ($this->_vendorPath === null) {
450 10
            $this->setVendorPath($this->getBasePath() . DIRECTORY_SEPARATOR . 'vendor');
451
        }
452
453 10
        return $this->_vendorPath;
454
    }
455
456
    /**
457
     * Sets the directory that stores vendor files.
458
     * @param string $path the directory that stores vendor files.
459
     */
460 2775
    public function setVendorPath($path)
461
    {
462 2775
        $this->_vendorPath = Yii::getAlias($path);
463 2775
        Yii::setAlias('@vendor', $this->_vendorPath);
0 ignored issues
show
Bug introduced by
It seems like $this->_vendorPath can also be of type boolean; however, yii\BaseYii::setAlias() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
464 2775
        Yii::setAlias('@bower', $this->_vendorPath . DIRECTORY_SEPARATOR . 'bower');
465 2775
        Yii::setAlias('@npm', $this->_vendorPath . DIRECTORY_SEPARATOR . 'npm');
466 2775
    }
467
468
    /**
469
     * Returns the time zone used by this application.
470
     * This is a simple wrapper of PHP function date_default_timezone_get().
471
     * If time zone is not configured in php.ini or application config,
472
     * it will be set to UTC by default.
473
     * @return string the time zone used by this application.
474
     * @see http://php.net/manual/en/function.date-default-timezone-get.php
475
     */
476 273
    public function getTimeZone()
477
    {
478 273
        return date_default_timezone_get();
479
    }
480
481
    /**
482
     * Sets the time zone used by this application.
483
     * This is a simple wrapper of PHP function date_default_timezone_set().
484
     * Refer to the [php manual](http://www.php.net/manual/en/timezones.php) for available timezones.
485
     * @param string $value the time zone used by this application.
486
     * @see http://php.net/manual/en/function.date-default-timezone-set.php
487
     */
488 372
    public function setTimeZone($value)
489
    {
490 372
        date_default_timezone_set($value);
491 372
    }
492
493
    /**
494
     * Returns the database connection component.
495
     * @return \yii\db\Connection the database connection.
496
     */
497 58
    public function getDb()
498
    {
499 58
        return $this->get('db');
500
    }
501
502
    /**
503
     * Returns the log dispatcher component.
504
     * @return \yii\log\Dispatcher the log dispatcher application component.
505
     */
506 6
    public function getLog()
507
    {
508 6
        return $this->get('log');
509
    }
510
511
    /**
512
     * Returns the error handler component.
513
     * @return \yii\web\ErrorHandler|\yii\console\ErrorHandler the error handler application component.
514
     */
515
    public function getErrorHandler()
516
    {
517
        return $this->get('errorHandler');
518
    }
519
520
    /**
521
     * Returns the cache component.
522
     * @return \yii\caching\CacheInterface the cache application component. Null if the component is not enabled.
523
     */
524
    public function getCache()
525
    {
526
        return $this->get('cache', false);
527
    }
528
529
    /**
530
     * Returns the formatter component.
531
     * @return \yii\i18n\Formatter the formatter application component.
532
     */
533 20
    public function getFormatter()
534
    {
535 20
        return $this->get('formatter');
536
    }
537
538
    /**
539
     * Returns the request component.
540
     * @return \yii\web\Request|\yii\console\Request the request component.
541
     */
542
    public function getRequest()
543
    {
544
        return $this->get('request');
545
    }
546
547
    /**
548
     * Returns the response component.
549
     * @return \yii\web\Response|\yii\console\Response the response component.
550
     */
551
    public function getResponse()
552
    {
553
        return $this->get('response');
554
    }
555
556
    /**
557
     * Returns the view object.
558
     * @return View|\yii\web\View the view application component that is used to render various view files.
559
     */
560 33
    public function getView()
561
    {
562 33
        return $this->get('view');
563
    }
564
565
    /**
566
     * Returns the URL manager for this application.
567
     * @return \yii\web\UrlManager the URL manager for this application.
568
     */
569 33
    public function getUrlManager()
570
    {
571 33
        return $this->get('urlManager');
572
    }
573
574
    /**
575
     * Returns the internationalization (i18n) component.
576
     * @return \yii\i18n\I18N the internationalization application component.
577
     */
578 484
    public function getI18n()
579
    {
580 484
        return $this->get('i18n');
581
    }
582
583
    /**
584
     * Returns the mailer component.
585
     * @return \yii\mail\MailerInterface the mailer application component.
586
     */
587
    public function getMailer()
588
    {
589
        return $this->get('mailer');
590
    }
591
592
    /**
593
     * Returns the auth manager for this application.
594
     * @return \yii\rbac\ManagerInterface the auth manager application component.
595
     * Null is returned if auth manager is not configured.
596
     */
597
    public function getAuthManager()
598
    {
599
        return $this->get('authManager', false);
600
    }
601
602
    /**
603
     * Returns the asset manager.
604
     * @return \yii\web\AssetManager the asset manager application component.
605
     */
606 6
    public function getAssetManager()
607
    {
608 6
        return $this->get('assetManager');
609
    }
610
611
    /**
612
     * Returns the security component.
613
     * @return \yii\base\Security the security application component.
614
     */
615 35
    public function getSecurity()
616
    {
617 35
        return $this->get('security');
618
    }
619
620
    /**
621
     * Returns the configuration of core application components.
622
     * @see set()
623
     */
624 2775
    public function coreComponents()
625
    {
626
        return [
627 2775
            'log' => ['class' => 'yii\log\Dispatcher'],
628
            'view' => ['class' => 'yii\web\View'],
629
            'formatter' => ['class' => 'yii\i18n\Formatter'],
630
            'i18n' => ['class' => 'yii\i18n\I18N'],
631
            'mailer' => ['class' => 'yii\swiftmailer\Mailer'],
632
            'urlManager' => ['class' => 'yii\web\UrlManager'],
633
            'assetManager' => ['class' => 'yii\web\AssetManager'],
634
            'security' => ['class' => 'yii\base\Security'],
635
        ];
636
    }
637
638
    /**
639
     * Terminates the application.
640
     * This method replaces the `exit()` function by ensuring the application life cycle is completed
641
     * before terminating the application.
642
     * @param int $status the exit status (value 0 means normal exit while other values mean abnormal exit).
643
     * @param Response $response the response to be sent. If not set, the default application [[response]] component will be used.
644
     * @throws ExitException if the application is in testing mode
645
     */
646 3
    public function end($status = 0, $response = null)
647
    {
648 3
        if ($this->state === self::STATE_BEFORE_REQUEST || $this->state === self::STATE_HANDLING_REQUEST) {
649
            $this->state = self::STATE_AFTER_REQUEST;
650
            $this->trigger(self::EVENT_AFTER_REQUEST);
651
        }
652
653 3
        if ($this->state !== self::STATE_SENDING_RESPONSE && $this->state !== self::STATE_END) {
654 3
            $this->state = self::STATE_END;
655 3
            $response = $response ?: $this->getResponse();
656 3
            $response->send();
657
        }
658
659 3
        if (YII_ENV_TEST) {
660 3
            throw new ExitException($status);
661
        }
662
663
        exit($status);
664
    }
665
666
    /**
667
     * Configures [[Yii::$container]] with the $config.
668
     *
669
     * @param array $config values given in terms of name-value pairs
670
     * @since 2.0.11
671
     */
672 1
    public function setContainer($config)
673
    {
674 1
        Yii::configure(Yii::$container, $config);
675 1
    }
676
}
677