Passed
Push — master ( f9c79d...d4a4c3 )
by Vladimir
02:25
created

Configurator::getDefaultIcons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link https://github.com/yiimaker/yii2-social-share
4
 * @copyright Copyright (c) 2017 Yii Maker
5
 * @license BSD 3-Clause License
6
 */
7
8
namespace ymaker\social\share\configurators;
9
10
use yii\base\BaseObject;
11
use yii\helpers\ArrayHelper;
12
use ymaker\social\share\drivers\Facebook;
13
use ymaker\social\share\drivers\GooglePlus;
14
use ymaker\social\share\drivers\LinkedIn;
15
use ymaker\social\share\drivers\Gmail;
16
use ymaker\social\share\drivers\WhatsApp;
17
use ymaker\social\share\drivers\Telegram;
18
use ymaker\social\share\drivers\Pinterest;
19
use ymaker\social\share\drivers\Tumblr;
20
use ymaker\social\share\drivers\Twitter;
21
use ymaker\social\share\drivers\Vkontakte;
22
23
/**
24
 * Configurator for social network drivers.
25
 *
26
 * @author Vladimir Kuprienko <[email protected]>
27
 * @since 1.0
28
 */
29
class Configurator extends BaseObject implements ConfiguratorInterface
30
{
31
    /**
32
     * @var array Configuration of social network drivers.
33
     */
34
    public $socialNetworks = [];
35
    /**
36
     * @var array CSS options for share links.
37
     */
38
    public $options = [];
39
    /**
40
     * @var bool Enable SEO options for share links.
41
     */
42
    public $enableSeoOptions = true;
43
    /**
44
     * @var array HTML attributes from this option will be applyed if `enableSeoOptions` is true.
45
     */
46
    public $seoOptions = [];
47
    /**
48
     * @var bool Enable default icons instead labels for social networks.
49
     */
50
    public $enableDefaultIcons = false;
51
    /**
52
     * @var array Configuration of icons for social network drivers.
53
     */
54
    public $icons = [];
55
56
    /**
57
     * @var array
58
     */
59
    private $_defaultIconsMap = [
60
        Vkontakte::class    => 'si si-vk',
61
        Facebook::class     => 'si si-facebook',
62
        Twitter::class      => 'si si-twitter',
63
        GooglePlus::class   => 'si si-google-plus',
64
        LinkedIn::class     => 'si si-linkedin',
65
        Pinterest::class    => 'si si-pinterest',
66
        Telegram::class     => 'si si-telegram',
67
        WhatsApp::class     => 'si si-whatsapp',
68
        Gmail::class        => 'si si-gmail',
69
        Tumblr::class       => 'si si-tumblr',
70
    ];
71
72
73
    /**
74
     * Set default values for special link options.
75
     */
76
    public function init()
77
    {
78
        if (empty($this->seoOptions)) {
79
            $this->seoOptions = [
80
                'target' => '_blank',
81
                'rel'    => 'noopener',
82
            ];
83
        }
84
        if ($this->enableDefaultIcons) {
85
            $this->icons = ArrayHelper::merge($this->_defaultIconsMap, $this->icons);
86
        }
87
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92
    public function getSocialNetworks()
93
    {
94
        return $this->socialNetworks;
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100
    public function getOptions()
101
    {
102
        return $this->enableSeoOptions
103
            ? ArrayHelper::merge($this->options, $this->seoOptions)
104
            : $this->options;
105
    }
106
107
    /**
108
     * Returns icon selector by driver name.
109
     *
110
     * @param string $driverName
111
     * @return string
112
     */
113
    public function getIconSelector($driverName)
114
    {
115
        return isset($this->icons[$driverName]) ? $this->icons[$driverName] : '';
116
    }
117
}
118