|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Pheanstalk\Structure; |
|
5
|
|
|
|
|
6
|
|
|
class Tube |
|
7
|
|
|
{ |
|
8
|
|
|
|
|
9
|
|
|
const SCHEDULER_TYPE_DEFAULT = 'default'; |
|
10
|
|
|
const SCHEDULER_TYPE_FIFO = 'fifo'; |
|
11
|
|
|
const SCHEDULER_TYPE_PRIO = 'prio'; |
|
12
|
|
|
|
|
13
|
|
|
const IS_DYNAMIC = 'yes'; |
|
14
|
|
|
const IS_NOT_DYNAMIC = 'no'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var int $id */ |
|
17
|
|
|
private $id; |
|
18
|
|
|
|
|
19
|
|
|
/** @var int $concurrency */ |
|
20
|
|
|
private $concurrency; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string $dynamic */ |
|
23
|
|
|
private $dynamic; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string $name */ |
|
26
|
|
|
private $name; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string $scheduler */ |
|
29
|
|
|
private $scheduler; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Tube constructor. |
|
33
|
|
|
* |
|
34
|
|
|
* @param string $name The name of the tube |
|
35
|
|
|
* @param int $concurrency The number of workflows that can be executed simultaneously |
|
36
|
|
|
* @param string $scheduler WIP |
|
37
|
|
|
* @param string|bool $dynamic Wether the tube is dynamic or not |
|
38
|
|
|
*/ |
|
39
|
9 |
|
public function __construct(string $name, int $concurrency, $scheduler = self::SCHEDULER_TYPE_DEFAULT, $dynamic = true) |
|
40
|
|
|
{ |
|
41
|
9 |
|
$this->name = $name; |
|
42
|
9 |
|
$this->concurrency = $concurrency; |
|
43
|
9 |
|
$this->scheduler = $scheduler; |
|
44
|
9 |
|
$this->setDynamic($dynamic); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return int |
|
49
|
|
|
*/ |
|
50
|
3 |
|
public function getId(): int |
|
51
|
|
|
{ |
|
52
|
3 |
|
return $this->id; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param int $id |
|
57
|
|
|
* |
|
58
|
|
|
* @return Tube |
|
59
|
|
|
*/ |
|
60
|
9 |
|
public function setId(int $id): Tube |
|
61
|
|
|
{ |
|
62
|
9 |
|
$this->id = $id; |
|
63
|
9 |
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return int |
|
68
|
|
|
*/ |
|
69
|
2 |
|
public function getConcurrency(): int |
|
70
|
|
|
{ |
|
71
|
2 |
|
return $this->concurrency; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param int $concurrency |
|
76
|
|
|
* |
|
77
|
|
|
* @return Tube |
|
78
|
|
|
*/ |
|
79
|
|
|
public function setConcurrency(int $concurrency): Tube |
|
80
|
|
|
{ |
|
81
|
|
|
$this->concurrency = $concurrency; |
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
2 |
|
public function getDynamic(): string |
|
89
|
|
|
{ |
|
90
|
2 |
|
$dynamic = $this->dynamic ?? true; |
|
91
|
2 |
|
return ($dynamic) ? self::IS_DYNAMIC : self::IS_NOT_DYNAMIC; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string|bool $dynamic |
|
96
|
|
|
* |
|
97
|
|
|
* @return Tube |
|
98
|
|
|
*/ |
|
99
|
9 |
|
public function setDynamic($dynamic): Tube |
|
100
|
|
|
{ |
|
101
|
9 |
|
if (!is_bool($dynamic)) { |
|
102
|
9 |
|
if ($dynamic === self::IS_NOT_DYNAMIC) { |
|
103
|
9 |
|
$dynamic = false; |
|
104
|
|
|
} else { |
|
105
|
8 |
|
$dynamic = true; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
9 |
|
$this->dynamic = $dynamic; |
|
|
|
|
|
|
109
|
9 |
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
9 |
|
public function getName(): string |
|
116
|
|
|
{ |
|
117
|
9 |
|
return $this->name; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param string $name |
|
122
|
|
|
* |
|
123
|
|
|
* @return Tube |
|
124
|
|
|
*/ |
|
125
|
1 |
|
public function setName(string $name): Tube |
|
126
|
|
|
{ |
|
127
|
1 |
|
$this->name = $name; |
|
128
|
1 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
2 |
|
public function getScheduler(): string |
|
135
|
|
|
{ |
|
136
|
2 |
|
return $this->scheduler ?? self::SCHEDULER_TYPE_DEFAULT; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param string $scheduler |
|
141
|
|
|
* |
|
142
|
|
|
* @return Tube |
|
143
|
|
|
*/ |
|
144
|
9 |
|
public function setScheduler(string $scheduler): Tube |
|
145
|
|
|
{ |
|
146
|
9 |
|
$this->scheduler = $scheduler; |
|
147
|
9 |
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.