Completed
Pull Request — master (#12929)
by Robert
48:37 queued 12:35
created

ConfigurableTrait::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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
 *
14
 * @author Robert Korulczyk <[email protected]>
15
 * @since 2.0.11
16
 */
17
trait ConfigurableTrait
18
{
19
    /**
20
     * Constructor.
21
     * The default implementation does two things:
22
     *
23
     * - Initializes the object with the given configuration `$config`.
24
     * - Call [[init()]].
25
     *
26
     * If this method is overridden in a child class, it is recommended that
27
     *
28
     * - the last parameter of the constructor is a configuration array, like `$config` here.
29
     * - call the parent implementation at the end of the constructor.
30
     *
31
     * @param array $config name-value pairs that will be used to initialize the object properties
32
     */
33
    public function __construct($config = [])
34
    {
35
        if (!empty($config)) {
36
            Yii::configure($this, $config);
37
        }
38
        $this->init();
39
    }
40
41
    /**
42
     * Initializes the object.
43
     * This method is invoked at the end of the constructor after the object is initialized with the
44
     * given configuration.
45
     */
46
    public function init()
47
    {
48
    }
49
}
50