1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
/** |
4
|
|
|
* Contains CommandToolsTrait trait. |
5
|
|
|
* |
6
|
|
|
* PHP version 7.0+ |
7
|
|
|
* |
8
|
|
|
* LICENSE: |
9
|
|
|
* This file is part of Yet Another Php Eve Api Library also know as Yapeal |
10
|
|
|
* which can be used to access the Eve Online API data and place it into a |
11
|
|
|
* database. |
12
|
|
|
* Copyright (C) 2014-2016 Michael Cummings |
13
|
|
|
* |
14
|
|
|
* This program is free software: you can redistribute it and/or modify it |
15
|
|
|
* under the terms of the GNU Lesser General Public License as published by the |
16
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
17
|
|
|
* option) any later version. |
18
|
|
|
* |
19
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
20
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
22
|
|
|
* for more details. |
23
|
|
|
* |
24
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
25
|
|
|
* along with this program. If not, see |
26
|
|
|
* <http://spdx.org/licenses/LGPL-3.0.html>. |
27
|
|
|
* |
28
|
|
|
* You should be able to find a copy of this license in the COPYING-LESSER.md |
29
|
|
|
* file. A copy of the GNU GPL should also be available in the COPYING.md file. |
30
|
|
|
* |
31
|
|
|
* @copyright 2014-2016 Michael Cummings |
32
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL |
33
|
|
|
* @author Michael Cummings <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
namespace Yapeal; |
36
|
|
|
|
37
|
|
|
use Yapeal\Container\ContainerInterface; |
38
|
|
|
use Yapeal\Exception\YapealDatabaseException; |
39
|
|
|
use Yapeal\Sql\CommonSqlQueries; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Trait CommandToolsTrait |
43
|
|
|
*/ |
44
|
|
|
trait CommonToolsTrait |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @return ContainerInterface |
48
|
|
|
* @throws \LogicException |
49
|
|
|
*/ |
50
|
2 |
|
public function getDic(): ContainerInterface |
51
|
|
|
{ |
52
|
2 |
|
if (!$this->dic instanceof ContainerInterface) { |
53
|
1 |
|
$mess = 'Tried to use dic before it was set'; |
54
|
1 |
|
throw new \LogicException($mess, 1); |
55
|
|
|
} |
56
|
1 |
|
return $this->dic; |
57
|
|
|
} |
58
|
|
|
/** |
59
|
|
|
* @param CommonSqlQueries $value |
60
|
|
|
* |
61
|
|
|
* @return self Fluent interface. |
62
|
|
|
*/ |
63
|
1 |
|
public function setCsq(CommonSqlQueries $value) |
64
|
|
|
{ |
65
|
1 |
|
$this->csq = $value; |
66
|
1 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
/** |
69
|
|
|
* @param ContainerInterface $value |
70
|
|
|
* |
71
|
|
|
* @return self Fluent interface. |
72
|
|
|
*/ |
73
|
1 |
|
public function setDic(ContainerInterface $value) |
74
|
|
|
{ |
75
|
1 |
|
$this->dic = $value; |
76
|
1 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
/** |
79
|
|
|
* @param \PDO $value |
80
|
|
|
* |
81
|
|
|
* @return self Fluent interface. |
82
|
|
|
*/ |
83
|
1 |
|
public function setPdo(\PDO $value) |
84
|
|
|
{ |
85
|
1 |
|
$this->pdo = $value; |
86
|
1 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
/** |
89
|
|
|
* @return CommonSqlQueries |
90
|
|
|
* @throws \LogicException |
91
|
|
|
*/ |
92
|
|
|
protected function getCsq(): CommonSqlQueries |
93
|
|
|
{ |
94
|
|
|
if (null === $this->csq) { |
95
|
|
|
$this->csq = $this->getDic()['Yapeal.Sql.CommonQueries']; |
96
|
|
|
} |
97
|
|
|
if (!$this->csq instanceof CommonSqlQueries) { |
98
|
|
|
$mess = 'Tried to use csq before it was set'; |
99
|
|
|
throw new \LogicException($mess, 1); |
100
|
|
|
} |
101
|
|
|
return $this->csq; |
102
|
|
|
} |
103
|
|
|
/** |
104
|
|
|
* @return \PDO |
105
|
|
|
* @throws \LogicException |
106
|
|
|
* @throws \Yapeal\Exception\YapealDatabaseException |
107
|
|
|
*/ |
108
|
|
|
protected function getPdo(): \PDO |
109
|
|
|
{ |
110
|
|
|
if (null === $this->pdo) { |
111
|
|
|
try { |
112
|
|
|
$this->pdo = $this->getDic()['Yapeal.Sql.Connection']; |
113
|
|
|
} catch (\PDOException $exc) { |
114
|
|
|
$mess = sprintf('Could NOT connect to database. Database error was (%1$s) %2$s', |
115
|
|
|
$exc->getCode(), |
116
|
|
|
$exc->getMessage()); |
117
|
|
|
throw new YapealDatabaseException($mess, 1, $exc); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
return $this->pdo; |
121
|
|
|
} |
122
|
|
|
/** |
123
|
|
|
* @var CommonSqlQueries $csq |
124
|
|
|
*/ |
125
|
|
|
protected $csq; |
126
|
|
|
/** |
127
|
|
|
* @var ContainerInterface $dic |
128
|
|
|
*/ |
129
|
|
|
protected $dic; |
130
|
|
|
/** |
131
|
|
|
* @var \PDO $pdo |
132
|
|
|
*/ |
133
|
|
|
protected $pdo; |
134
|
|
|
} |
135
|
|
|
|