Completed
Push — master ( b0162d...03d53b )
by Alexander
10:45 queued 30s
created

Application::bootstrap()   D

Complexity

Conditions 17
Paths 322

Size

Total Lines 52
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 29.7014

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 22
cts 34
cp 0.6471
rs 4.4034
c 0
b 0
f 0
cc 17
eloc 35
nc 322
nop 0
crap 29.7014

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 2763
    public function __construct($config = [])
196
    {
197 2763
        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 2763
        static::setInstance($this);
199
200 2763
        $this->state = self::STATE_BEGIN;
201
202 2763
        $this->preInit($config);
203
204 2763
        $this->registerErrorHandler($config);
205
206 2763
        Component::__construct($config);
207 2763
    }
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 2763
    public function preInit(&$config)
218
    {
219 2763
        if (!isset($config['id'])) {
220
            throw new InvalidConfigException('The "id" configuration for the Application is required.');
221
        }
222 2763
        if (isset($config['basePath'])) {
223 2763
            $this->setBasePath($config['basePath']);
224 2763
            unset($config['basePath']);
225
        } else {
226
            throw new InvalidConfigException('The "basePath" configuration for the Application is required.');
227
        }
228
229 2763
        if (isset($config['vendorPath'])) {
230 2757
            $this->setVendorPath($config['vendorPath']);
231 2757
            unset($config['vendorPath']);
232
        } else {
233
            // set "@vendor"
234 10
            $this->getVendorPath();
235
        }
236 2763
        if (isset($config['runtimePath'])) {
237
            $this->setRuntimePath($config['runtimePath']);
238
            unset($config['runtimePath']);
239
        } else {
240
            // set "@runtime"
241 2763
            $this->getRuntimePath();
242
        }
243
244 2763
        if (isset($config['timeZone'])) {
245 370
            $this->setTimeZone($config['timeZone']);
246 370
            unset($config['timeZone']);
247 2399
        } elseif (!ini_get('date.timezone')) {
248
            $this->setTimeZone('UTC');
249
        }
250
251 2763
        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 2763
        foreach ($this->coreComponents() as $id => $component) {
259 2763
            if (!isset($config['components'][$id])) {
260 2763
                $config['components'][$id] = $component;
261 398
            } elseif (is_array($config['components'][$id]) && !isset($config['components'][$id]['class'])) {
262 2763
                $config['components'][$id]['class'] = $component['class'];
263
            }
264
        }
265 2763
    }
266
267
    /**
268
     * @inheritdoc
269
     */
270 2763
    public function init()
271
    {
272 2763
        $this->state = self::STATE_INIT;
273 2763
        $this->bootstrap();
274 2763
    }
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 2763
    protected function bootstrap()
282
    {
283 2763
        if ($this->extensions === null) {
284 2763
            $file = Yii::getAlias('@vendor/yiisoft/extensions.php');
285 2763
            $this->extensions = is_file($file) ? include $file : [];
286
        }
287 2763
        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 2763
        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 2763
    }
333
334
    /**
335
     * Registers the errorHandler component as a PHP error handler.
336
     * @param array $config application config
337
     */
338 2763
    protected function registerErrorHandler(&$config)
339
    {
340 2763
        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 2763
    }
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
    public function getUniqueId()
357
    {
358
        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 2763
    public function setBasePath($path)
369
    {
370 2763
        parent::setBasePath($path);
371 2763
        Yii::setAlias('@app', $this->getBasePath());
372 2763
    }
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());
0 ignored issues
show
Documentation introduced by
$this->getRequest() is of type object|null, but the function expects a object<yii\base\Request>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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 2763
    public function getRuntimePath()
422
    {
423 2763
        if ($this->_runtimePath === null) {
424 2763
            $this->setRuntimePath($this->getBasePath() . DIRECTORY_SEPARATOR . 'runtime');
425
        }
426
427 2763
        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 2763
    public function setRuntimePath($path)
435
    {
436 2763
        $this->_runtimePath = Yii::getAlias($path);
437 2763
        Yii::setAlias('@runtime', $this->_runtimePath);
438 2763
    }
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 2763
    public function setVendorPath($path)
461
    {
462 2763
        $this->_vendorPath = Yii::getAlias($path);
463 2763
        Yii::setAlias('@vendor', $this->_vendorPath);
464 2763
        Yii::setAlias('@bower', $this->_vendorPath . DIRECTORY_SEPARATOR . 'bower');
465 2763
        Yii::setAlias('@npm', $this->_vendorPath . DIRECTORY_SEPARATOR . 'npm');
466 2763
    }
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 271
    public function getTimeZone()
477
    {
478 271
        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 370
    public function setTimeZone($value)
489
    {
490 370
        date_default_timezone_set($value);
491 370
    }
492
493
    /**
494
     * Returns the database connection component.
495
     * @return \yii\db\Connection the database connection.
496
     */
497 52
    public function getDb()
498
    {
499 52
        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 31
    public function getUrlManager()
570
    {
571 31
        return $this->get('urlManager');
572
    }
573
574
    /**
575
     * Returns the internationalization (i18n) component
576
     * @return \yii\i18n\I18N the internationalization application component.
577
     */
578 474
    public function getI18n()
579
    {
580 474
        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 33
    public function getSecurity()
616
    {
617 33
        return $this->get('security');
618
    }
619
620
    /**
621
     * Returns the configuration of core application components.
622
     * @see set()
623
     */
624 2763
    public function coreComponents()
625
    {
626
        return [
627 2763
            '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