1
|
|
|
<?php |
2
|
|
|
namespace Workana\AsyncJobs; |
3
|
|
|
|
4
|
|
|
use InvalidArgumentException; |
5
|
|
|
use Workana\AsyncJobs\Retry\BinaryExponentialBackoff; |
6
|
|
|
use Workana\AsyncJobs\Router\DefaultRouter; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Carlos Frutos <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class Configuration |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
protected $attributes; |
17
|
|
|
|
18
|
|
|
public function __construct(array $options) |
19
|
|
|
{ |
20
|
|
|
$this->attributes = $options + [ |
21
|
|
|
'routerClass' => DefaultRouter::class, |
22
|
|
|
'driverClass' => null, |
23
|
|
|
'retryStrategyClass' => BinaryExponentialBackoff::class, |
24
|
|
|
'normalizerClasses' => [], |
25
|
|
|
'defaultQueueName' => 'default', |
26
|
|
|
'useDoctrine' => false, |
27
|
|
|
'sync' => false, |
28
|
|
|
'dispatchingRules' => [], |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
if (empty($this->attributes['driverClass'])) { |
32
|
|
|
throw new InvalidArgumentException('Driver class must be specified'); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get router class |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function getRouterClass() |
42
|
|
|
{ |
43
|
|
|
return $this->attributes['routerClass']; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get driver class |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function getDriverClass() |
52
|
|
|
{ |
53
|
|
|
return $this->attributes['driverClass']; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get retry strategy class |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function getRetryStrategyClass() |
62
|
|
|
{ |
63
|
|
|
return $this->attributes['retryStrategyClass']; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get normalizer classes |
68
|
|
|
* |
69
|
|
|
* @return string[] |
70
|
|
|
*/ |
71
|
|
|
public function getNormalizerClasses() |
72
|
|
|
{ |
73
|
|
|
return $this->attributes['normalizerClasses']; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getDefaultQueueName() |
80
|
|
|
{ |
81
|
|
|
return $this->attributes['defaultQueueName']; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Is on sync mode for job dispatching |
86
|
|
|
* |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function isSync() |
90
|
|
|
{ |
91
|
|
|
return $this->attributes['sync']; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
|
|
public function isUsingDoctrine() |
98
|
|
|
{ |
99
|
|
|
return $this->attributes['useDoctrine']; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get dispatching rules |
104
|
|
|
* |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function getDispatchingRules() |
108
|
|
|
{ |
109
|
|
|
return $this->attributes['dispatchingRules']; |
110
|
|
|
} |
111
|
|
|
} |