|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the PhpBotFramework. |
|
5
|
|
|
* |
|
6
|
|
|
* PhpBotFramework is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU Lesser General Public License as |
|
8
|
|
|
* published by the Free Software Foundation, version 3. |
|
9
|
|
|
* |
|
10
|
|
|
* PhpBotFramework is distributed in the hope that it will be useful, but |
|
11
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13
|
|
|
* Lesser General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace PhpBotFramework\Database; |
|
20
|
|
|
|
|
21
|
|
|
use PhpBotFramework\Exceptions\BotException; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* \class Getter Database Getter |
|
25
|
|
|
* \brief Get PDO and redis object from bot, if any. |
|
26
|
|
|
*/ |
|
27
|
|
|
trait Getter |
|
28
|
|
|
{ |
|
29
|
|
|
/** @internal |
|
30
|
|
|
* \brief Database handler object. */ |
|
31
|
|
|
public $database; |
|
32
|
|
|
|
|
33
|
|
|
/** @internal |
|
34
|
|
|
* \brief Redis object. */ |
|
35
|
|
|
public $redis; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* \brief Get PDO object. |
|
39
|
|
|
* @return PDO Connection object. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getPdo() : \PDO |
|
42
|
|
|
{ |
|
43
|
|
|
if (!isset($this->database)) { |
|
44
|
|
|
throw new BotException("Database connection has not been set"); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this->database->pdo; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* \brief Get Redis object. |
|
52
|
|
|
* @return Redis Conneciton object. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getRedis() : \Redis |
|
55
|
|
|
{ |
|
56
|
|
|
if (!isset($this->redis)) { |
|
57
|
|
|
throw new BotException("Redis connection has not been set"); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this->redis; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|