Passed
Push — master ( 1df131...0e60b7 )
by Alexey
02:54
created

MapAsset::setMaps()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace backend\widgets\map\jvector\assets;
4
5
use yii\base\InvalidArgumentException;
6
use yii\web\AssetBundle;
7
8
/**
9
 * Class Map
10
 *
11
 * @package backend\widgets\map\jvector\assets
12
 */
13
class MapAsset extends AssetBundle
14
{
15
    /** @var array */
16
    public static $maps = [];
17
    /** @var string */
18
    public static $mapName = 'world_mill_en';
19
20
    /** @var array|null */
21
    private $mapsArray;
22
    /** @var string|null */
23
    private $map;
24
25
    /**
26
     * @inheritDoc
27
     */
28
    public function init()
29
    {
30
        parent::init();
31
        $this->sourcePath = __DIR__ . '/src/maps';
32
        $this->setMaps(self::$maps);
33
        $maps = $this->getMaps();
34
        if (is_array($maps) && !empty($maps[self::$mapName])) {
35
            $this->setMap($maps[self::$mapName]);
36
            $this->js = [
37
                'jquery-jvectormap-' . $this->getMap() . '.js'
38
            ];
39
        } else {
40
            throw new InvalidArgumentException(__class__ . ': Incorrect map name: "' . self::$mapName . '"');
41
        }
42
    }
43
44
    /**
45
     * @param array $maps
46
     */
47
    public function setMaps($maps = [])
48
    {
49
        $this->mapsArray = $maps;
50
    }
51
52
    /**
53
     * @return array|null
54
     */
55
    public function getMaps()
56
    {
57
        return $this->mapsArray;
58
    }
59
60
    /**
61
     * @param string $value
62
     */
63
    public function setMap($value = '')
64
    {
65
        $this->map = $value;
66
    }
67
68
    /**
69
     * @return string|null
70
     */
71
    public function getMap()
72
    {
73
        return $this->map;
74
    }
75
76
    /**
77
     * @var string[]
78
     */
79
    public $depends = [
80
        JVectorMapAsset::class,
81
    ];
82
}
83