1
|
|
|
<?php |
2
|
|
|
namespace Dazzle\Redis\Driver; |
3
|
|
|
|
4
|
|
|
use Clue\Redis\Protocol\Model\ModelInterface; |
5
|
|
|
use Clue\Redis\Protocol\Model\Request; |
|
|
|
|
6
|
|
|
use Clue\Redis\Protocol\Parser\RequestParser; |
7
|
|
|
use Clue\Redis\Protocol\Parser\ResponseParser; |
8
|
|
|
use Clue\Redis\Protocol\Serializer\RecursiveSerializer; |
9
|
|
|
|
10
|
|
|
class Driver implements DriverInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var RequestParser |
14
|
|
|
*/ |
15
|
|
|
protected $requestParser; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var ResponseParser |
19
|
|
|
*/ |
20
|
|
|
protected $responseParser; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var RecursiveSerializer |
24
|
|
|
*/ |
25
|
|
|
protected $serializer; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
$this->requestParser = new RequestParser(); |
33
|
|
|
$this->responseParser = new ResponseParser(); |
34
|
|
|
$this->serializer = new RecursiveSerializer(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @inheritDoc |
39
|
|
|
*/ |
40
|
1 |
|
public function commands(Request $request) |
41
|
|
|
{ |
42
|
1 |
|
return $this->serializer->getRequestMessage( |
43
|
1 |
|
$request->getCommand(), |
44
|
1 |
|
$request->getArgs() |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return RecursiveSerializer |
50
|
|
|
*/ |
51
|
|
|
public function getSerializer() |
52
|
|
|
{ |
53
|
|
|
return $this->serializer; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return RequestParser |
58
|
|
|
*/ |
59
|
|
|
public function getRequestParser() |
60
|
|
|
{ |
61
|
|
|
return $this->requestParser; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return ResponseParser |
66
|
|
|
*/ |
67
|
|
|
public function getResponseParser() |
68
|
|
|
{ |
69
|
|
|
return $this->responseParser; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param $data |
74
|
|
|
* @return ModelInterface[] |
75
|
|
|
*/ |
76
|
1 |
|
public function parseResponse($data) |
77
|
|
|
{ |
78
|
1 |
|
return $this->responseParser->pushIncoming($data); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $data |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function buildResponse($data) |
86
|
|
|
{ |
87
|
|
|
return $this->serializer->getReplyMessage($data); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: