1 | <?php |
||
23 | abstract class AbstractConnection extends Component implements ConnectionInterface |
||
24 | { |
||
25 | const EVENT_AFTER_OPEN = 'afterOpen'; |
||
26 | |||
27 | /** |
||
28 | * @var string to be specified in concrete implementation |
||
29 | */ |
||
30 | public $queryBuilderClass; |
||
31 | |||
32 | public $requestClass = Request::class; |
||
33 | |||
34 | public $commandClass = Command::class; |
||
35 | |||
36 | public $queryClass = Query::class; |
||
37 | |||
38 | public $activeQueryClass = ActiveQuery::class; |
||
39 | |||
40 | public static $dbname = 'hiart'; |
||
41 | |||
42 | public $name = 'hiart'; |
||
43 | |||
44 | public $userAgent = 'HiArt/0.x'; |
||
45 | |||
46 | public $baseUri; |
||
47 | |||
48 | /** |
||
49 | * @var array transport config will be used in Request for handler or proxy request |
||
50 | */ |
||
51 | public $config = []; |
||
52 | |||
53 | /** |
||
54 | * @var object request handler common for all requests of this connection |
||
55 | */ |
||
56 | protected $_handler; |
||
57 | |||
58 | /** |
||
59 | * @var AbstractQueryBuilder the query builder for this connection |
||
60 | */ |
||
61 | protected $_builder; |
||
62 | |||
63 | /** |
||
64 | * @var array authorization config |
||
65 | */ |
||
66 | protected $_auth = []; |
||
67 | |||
68 | /** |
||
69 | * @var bool is auth disabled |
||
70 | */ |
||
71 | protected $_disabledAuth = false; |
||
72 | |||
73 | /** |
||
74 | * @var Closure callback to test if API response has error |
||
75 | * The function signature: `function ($response)` |
||
76 | * Must return `null`, if the response does not contain an error |
||
77 | */ |
||
78 | protected $_errorChecker; |
||
79 | |||
80 | /** |
||
81 | * @param null $name |
||
82 | * @return ConnectionInterface|AbstractConnection |
||
83 | */ |
||
84 | 3 | public static function getDb($name = null, $class = ConnectionInterface::class) |
|
85 | { |
||
86 | 3 | if ($name) { |
|
87 | return Yii::$app->get($name); |
||
88 | } |
||
89 | 3 | if (Yii::$container->hasSingleton($class)) { |
|
90 | 2 | return Yii::$container->get($class); |
|
91 | } |
||
92 | |||
93 | 1 | return Yii::$app->get(static::$dbname); |
|
94 | } |
||
95 | |||
96 | 1 | public function setAuth($auth) |
|
100 | |||
101 | /** |
||
102 | * Returns auth settings. |
||
103 | * @return array |
||
104 | */ |
||
105 | 2 | public function getAuth() |
|
116 | |||
117 | public function disableAuth() |
||
121 | |||
122 | public function enableAuth() |
||
126 | |||
127 | /** |
||
128 | * Closes the connection when this component is being serialized. |
||
129 | * @return array |
||
130 | */ |
||
131 | public function __sleep() |
||
135 | |||
136 | /** |
||
137 | * Returns the name of the DB driver for the current [[dsn]]. |
||
138 | * @return string name of the DB driver |
||
139 | */ |
||
140 | public function getDriverName() |
||
144 | |||
145 | /** |
||
146 | * Creates a command for execution. |
||
147 | * @param array $config the configuration for the Command class |
||
148 | * @return Command the DB command |
||
149 | */ |
||
150 | 2 | public function createCommand(array $config = []) |
|
156 | |||
157 | /** |
||
158 | * @return AbstractQueryBuilder the query builder for this connection |
||
159 | */ |
||
160 | 3 | public function getQueryBuilder() |
|
168 | |||
169 | /** |
||
170 | * Handler is created and set by request. |
||
171 | * @see setHandler |
||
172 | * @return object |
||
173 | */ |
||
174 | public function getHandler() |
||
178 | |||
179 | /** |
||
180 | * Requests use this function to keep request handler. |
||
181 | * @param object $handler |
||
182 | */ |
||
183 | public function setHandler($handler) |
||
187 | |||
188 | /** |
||
189 | * @return boolean |
||
190 | */ |
||
191 | public function isDisabledAuth() |
||
195 | |||
196 | /** |
||
197 | * @param boolean $disabledAuth |
||
198 | */ |
||
199 | public function setDisabledAuth($disabledAuth) |
||
203 | |||
204 | /** |
||
205 | * Try to decode error information if it is valid json, return it if not. |
||
206 | * @param $body |
||
207 | * @return mixed |
||
208 | */ |
||
209 | protected function decodeErrorBody($body) |
||
223 | |||
224 | /** |
||
225 | * Setter for errorChecker. |
||
226 | * @param Closure $checker |
||
227 | */ |
||
228 | public function setErrorChecker($checker) |
||
232 | |||
233 | /** |
||
234 | * Checks response method and raises exception if error found. |
||
235 | * @param ResponseInterface $response response data from API |
||
236 | * @throws ResponseErrorException when response is invalid |
||
237 | */ |
||
238 | 2 | public function checkResponse(ResponseInterface $response) |
|
250 | |||
251 | /** |
||
252 | * Method checks whether the response is an error. |
||
253 | * |
||
254 | * @param ResponseInterface $response |
||
255 | * @return false|string the error text or boolean `false`, when the response is not an error |
||
256 | */ |
||
257 | abstract public function getResponseError(ResponseInterface $response); |
||
258 | |||
259 | protected $baseUriChecked; |
||
260 | |||
261 | /** |
||
262 | * Return API base uri. |
||
263 | * Adds trailing slash if uri is domain only. |
||
264 | * @return string |
||
265 | */ |
||
266 | 4 | public function getBaseUri() |
|
277 | |||
278 | 2 | public function getUserAgent() |
|
282 | } |
||
283 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..