Passed
Push — devel-3.0 ( 6b6d4a...0e3c8b )
by Rubén
03:12
created

PluginBase::setData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Plugin;
26
27
use Psr\Container\ContainerInterface;
28
use SP\Services\Plugin\PluginService;
29
30
/**
31
 * Class PluginBase
32
 *
33
 * @package SP\Plugin
34
 */
35
abstract class PluginBase implements PluginInterface
36
{
37
    /**
38
     * @var string Directorio base
39
     */
40
    protected $base;
41
    /**
42
     * @var string Tipo de plugin
43
     */
44
    protected $type;
45
    /**
46
     * @var string
47
     */
48
    protected $themeDir;
49
    /**
50
     * @var mixed
51
     */
52
    protected $data;
53
    /**
54
     * @var int
55
     */
56
    protected $enabled;
57
    /**
58
     * @var PluginService
59
     */
60
    private $pluginService;
61
62
    /**
63
     * PluginBase constructor.
64
     *
65
     * @param ContainerInterface $dic
66
     */
67
    public final function __construct(ContainerInterface $dic)
68
    {
69
        $this->pluginService = $dic->get(PluginService::class);
70
        $this->init($dic);
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getType()
77
    {
78
        return $this->type;
79
    }
80
81
    /**
82
     * @param string $type
83
     */
84
    public function setType($type)
85
    {
86
        $this->type = $type;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getThemeDir()
93
    {
94
        return $this->themeDir;
95
    }
96
97
    /**
98
     * @return mixed
99
     */
100
    public function getData()
101
    {
102
        return $this->data;
103
    }
104
105
    /**
106
     * @return int
107
     */
108
    public function getEnabled()
109
    {
110
        return (int)$this->enabled;
111
    }
112
113
    /**
114
     * @param int $enabled
115
     */
116
    public function setEnabled($enabled)
117
    {
118
        $this->enabled = (int)$enabled;
119
    }
120
121
    /**
122
     * @throws \SP\Core\Exceptions\ConstraintException
123
     * @throws \SP\Core\Exceptions\QueryException
124
     * @throws \SP\Repositories\NoSuchItemException
125
     */
126
    final public function saveData()
127
    {
128
        $pluginData = $this->pluginService->getByName($this->getName());
129
        $pluginData->setData(serialize($this->data));
130
131
        return $this->pluginService->update($pluginData);
132
    }
133
134
    /**
135
     * Establecer las locales del plugin
136
     */
137
    protected function setLocales()
138
    {
139
        $locales = $this->getBase() . DIRECTORY_SEPARATOR . 'locales';
140
        $name = strtolower($this->getName());
141
142
        bindtextdomain($name, $locales);
143
        bind_textdomain_codeset($name, 'UTF-8');
144
    }
145
146
    /**
147
     * @return string
148
     */
149
    public function getBase()
150
    {
151
        return $this->base;
152
    }
153
}