/
AbstractIndexPopulateEvent.php
80 lines (70 loc) · 1.63 KB
/
AbstractIndexPopulateEvent.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/*
* This file is part of the FOSElasticaBundle package.
*
* (c) FriendsOfSymfony <https://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\ElasticaBundle\Event;
/**
* Index Populate Event.
*
* @author Oleg Andreyev <oleg.andreyev@intexsys.lv>
*
* @phpstan-type TOptions = array{
* delete: bool,
* reset: bool,
* ignore_errors: bool,
* sleep: int,
* first_page: int,
* max_per_page: int,
* last_page?: int,
* indexName?: string,
* pager_persister: string
* }
*/
abstract class AbstractIndexPopulateEvent extends AbstractIndexEvent
{
/**
* @var bool
*/
protected $reset;
/**
* @var array
*
* @phpstan-var TOptions
*/
protected $options;
/**
* @phpstan-param TOptions $options
*/
public function __construct(string $index, bool $reset, array $options)
{
parent::__construct($index);
$this->reset = $reset;
$this->options = $options;
}
public function isReset(): bool
{
return $this->reset;
}
/**
* @phpstan-return TOptions
*/
public function getOptions(): array
{
return $this->options;
}
/**
* @throws \InvalidArgumentException if option does not exist
*/
public function getOption(string $name)
{
if (!isset($this->options[$name])) {
throw new \InvalidArgumentException(\sprintf('The "%s" option does not exist.', $name));
}
return $this->options[$name];
}
}