-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathConfigurableDbalProtocol.php
More file actions
64 lines (56 loc) · 2.61 KB
/
ConfigurableDbalProtocol.php
File metadata and controls
64 lines (56 loc) · 2.61 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Smartbox\Integration\FrameworkBundle\Components\DB\Dbal;
use Smartbox\Integration\FrameworkBundle\Configurability\DescriptableInterface;
use Smartbox\Integration\FrameworkBundle\Core\Protocols\Protocol;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ConfigurableDbalProtocol extends Protocol implements DescriptableInterface
{
const OPTION_METHOD = 'method';
const OPTION_STOP_ON_NO_RESULTS = 'stop_on_no_results';
const OPTION_DB_CONNECTION_NAME = 'db_connection_name';
const OPTION_SLEEP_TIME = 'sleep_time_ms';
const OPTION_INACTIVITY_TRIGGER = 'inactivity_trigger_sec';
/**
* Get static default options.
*
* @return array Array with option name, description, and options (optional)
*/
public function getOptionsDescriptions()
{
return array_merge(parent::getOptionsDescriptions(), [
self::OPTION_METHOD => ['Method to be executed in the consumer/producer', []],
self::OPTION_STOP_ON_NO_RESULTS => ['Consumer should stop on when all the records have been processed.', []],
self::OPTION_DB_CONNECTION_NAME => ['Option to chose which DB connection the consumer/producer should use', []],
self::OPTION_SLEEP_TIME => ['Duration of the pause made in the consume loop, when nothing to do (slow mode), in milliseconds.', []],
self::OPTION_INACTIVITY_TRIGGER => ['Inactivity duration before switching to slow mode, in seconds.', []],
]);
}
/**
* With this method this class can configure an OptionsResolver that will be used to validate the options.
*
* @param OptionsResolver $resolver
*/
public function configureOptionsResolver(OptionsResolver $resolver)
{
parent::configureOptionsResolver($resolver);
$resolver->setRequired([self::OPTION_METHOD]);
$resolver->setDefaults([
self::OPTION_STOP_ON_NO_RESULTS => false,
self::OPTION_DB_CONNECTION_NAME => '',
self::OPTION_SLEEP_TIME => 100,
self::OPTION_INACTIVITY_TRIGGER => 10,
]);
$resolver->setAllowedTypes(self::OPTION_METHOD, ['string']);
$resolver->setAllowedTypes(self::OPTION_STOP_ON_NO_RESULTS, ['bool']);
$resolver->setAllowedTypes(self::OPTION_DB_CONNECTION_NAME, 'string');
$resolver->setAllowedTypes(self::OPTION_SLEEP_TIME, 'numeric');
$resolver->setAllowedTypes(self::OPTION_INACTIVITY_TRIGGER, 'numeric');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return 'Specialized protocol to interact with databases using the doctrine DBAL';
}
}