1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the PommProject/Foundation package. |
4
|
|
|
* |
5
|
|
|
* (c) 2014 - 2017 Grégoire HUBERT <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace PommProject\Foundation\QueryManager; |
11
|
|
|
|
12
|
|
|
use PommProject\Foundation\Client\ClientPooler; |
13
|
|
|
use PommProject\Foundation\Client\ClientInterface; |
14
|
|
|
use PommProject\Foundation\Exception\FoundationException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* QueryManagerPooler |
18
|
|
|
* |
19
|
|
|
* Pooler for the query_manager clients type. |
20
|
|
|
* |
21
|
|
|
* @package Foundation |
22
|
|
|
* @copyright 2014 - 2017 Grégoire HUBERT |
23
|
|
|
* @author Grégoire HUBERT |
24
|
|
|
* @license X11 {@link http://opensource.org/licenses/mit-license.php} |
25
|
|
|
* @see ClientPooler |
26
|
|
|
*/ |
27
|
|
|
class QueryManagerPooler extends ClientPooler |
28
|
|
|
{ |
29
|
|
|
protected $listeners = []; |
30
|
|
|
/** |
31
|
|
|
* getPoolerType |
32
|
|
|
* |
33
|
|
|
* @see ClientPoolerInterface |
34
|
|
|
*/ |
35
|
|
|
public function getPoolerType() |
36
|
|
|
{ |
37
|
|
|
return 'query_manager'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* getClientFromPool |
42
|
|
|
* |
43
|
|
|
* @see ClientPooler |
44
|
|
|
* @return ClientInterface |
45
|
|
|
*/ |
46
|
|
|
protected function getClientFromPool($client) |
47
|
|
|
{ |
48
|
|
|
return $this |
49
|
|
|
->getSession() |
50
|
|
|
->getClient($this->getPoolerType(), trim($client, "\\")) |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* createClient |
56
|
|
|
* |
57
|
|
|
* @see ClientPooler |
58
|
|
|
* @param string $client Client class name |
59
|
|
|
* @throws FoundationException |
60
|
|
|
* @return ClientInterface |
61
|
|
|
*/ |
62
|
|
|
protected function createClient($client) |
63
|
|
|
{ |
64
|
|
|
try { |
65
|
|
|
new \ReflectionClass($client); |
66
|
|
|
} catch (\ReflectionException $e) { |
67
|
|
|
throw new FoundationException(sprintf("Could not load class '%s'.", $client), null, $e); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$client_instance = new $client(); |
71
|
|
|
|
72
|
|
|
return $client_instance; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* getPoolerType |
77
|
|
|
* |
78
|
|
|
* @see ClientPooler |
79
|
|
|
* @param null|string $client |
80
|
|
|
* @return \PommProject\Foundation\Client\Client |
81
|
|
|
*/ |
82
|
|
|
public function getClient($client = null) |
83
|
|
|
{ |
84
|
|
|
if ($client === null) { |
85
|
|
|
$client = '\PommProject\Foundation\QueryManager\SimpleQueryManager'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return parent::getClient($client); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|