1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Rpc\Request; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class RpcRequestCollection implements RpcRequestCollectionInterface, \IteratorAggregate, \Countable |
7
|
|
|
{ |
8
|
|
|
private $priority; |
9
|
|
|
public $requests = []; |
10
|
|
|
|
11
|
|
|
public function __construct($priority = RpcRequestCollectionInterface::PRIORITY_LOW) |
12
|
|
|
{ |
13
|
|
|
$this->priority = $this->changePriority($priority); |
|
|
|
|
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function getIterator() |
17
|
|
|
{ |
18
|
|
|
return new \ArrayIterator($this->requests); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function count() |
22
|
|
|
{ |
23
|
|
|
return count($this->requests); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function add(RpcRequestInterface $request) |
27
|
|
|
{ |
28
|
|
|
$key = array_search($request, $this->requests, true); |
29
|
|
|
|
30
|
|
|
if ($key !== false) { |
31
|
|
|
unset($this->requests[$key]); |
32
|
|
|
} |
33
|
|
|
$this->requests[] = $request; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function all() |
37
|
|
|
{ |
38
|
|
|
return $this->requests; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function get($id) |
42
|
|
|
{ |
43
|
|
|
if (isset($this->requests[$id])) { |
44
|
|
|
return $this->requests[$id]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param RpcRequest $request |
52
|
|
|
* @return string|int|null |
53
|
|
|
*/ |
54
|
|
|
public function getRequestIndex(RpcRequest $request) |
55
|
|
|
{ |
56
|
|
|
return array_search($request, $this->requests); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param $id |
61
|
|
|
*/ |
62
|
|
|
public function remove($id) |
63
|
|
|
{ |
64
|
|
|
unset($this->requests[$id]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param RpcRequestCollection $collection |
69
|
|
|
*/ |
70
|
|
|
public function addCollection(RpcRequestCollection $collection) |
71
|
|
|
{ |
72
|
|
|
foreach ($collection->all() as $id => $request) { |
73
|
|
|
unset($this->requests[$id]); |
74
|
|
|
$this->requests[$id] = $request; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param $priorityNumber |
80
|
|
|
*/ |
81
|
|
|
public function changePriority($priorityNumber) |
82
|
|
|
{ |
83
|
|
|
if (!decoct(octdec($priorityNumber) == $priorityNumber)) { |
84
|
|
|
$priorityNumber = decoct($priorityNumber); |
85
|
|
|
} |
86
|
|
|
$this->priority = $priorityNumber; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Return octect priority |
91
|
|
|
* |
92
|
|
|
* @return int |
93
|
|
|
*/ |
94
|
|
|
public function getPriority() |
95
|
|
|
{ |
96
|
|
|
return $this->priority; |
97
|
|
|
} |
98
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.