-
Notifications
You must be signed in to change notification settings - Fork 1
/
QueueClientAdapterFactory.php
49 lines (44 loc) · 1.59 KB
/
QueueClientAdapterFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace ReputationVIP\Bundle\QueueClientBundle;
use Aws\Sqs\SqsClient;
use ReputationVIP\QueueClient\Adapter\AdapterInterface;
use ReputationVIP\QueueClient\Adapter\FileAdapter;
use ReputationVIP\QueueClient\Adapter\MemoryAdapter;
use ReputationVIP\QueueClient\Adapter\NullAdapter;
use ReputationVIP\QueueClient\Adapter\SQSAdapter;
use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface;
class QueueClientAdapterFactory
{
/**
* @param array $config
* @param PriorityHandlerInterface $priorityHandler
* @return null|AdapterInterface
*/
public function get($config, $priorityHandler) {
$adapter = null;
switch ($config['type']) {
case 'null':
$adapter = new NullAdapter();
break;
case 'file':
$adapter = new FileAdapter($config['repository'], $priorityHandler);
break;
case 'sqs':
$adapter = new SQSAdapter(SqsClient::factory(array(
'region' => $config['region'],
'version' => $config['version'],
'credentials' => array(
'key' => $config['key'],
'secret' => $config['secret'],
),
)), $priorityHandler);
break;
case 'memory':
$adapter = new MemoryAdapter($priorityHandler);
break;
default:
throw new \InvalidArgumentException('Unknown handler type : ' . $config['type']);
}
return $adapter;
}
}