1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elastica\Processor; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Elastica Date Processor. |
7
|
|
|
* |
8
|
|
|
* @author Federico Panini <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/date-processor.html |
11
|
|
|
*/ |
12
|
|
|
class DateProcessor extends AbstractProcessor |
13
|
|
|
{ |
14
|
|
|
public const DEFAULT_TARGET_FIELD_VALUE = '@timestamp'; |
15
|
|
|
public const DEFAULT_TIMEZONE_VALUE = 'UTC'; |
16
|
|
|
public const DEFAULT_LOCALE_VALUE = 'ENGLISH'; |
17
|
|
|
|
18
|
|
|
public function __construct(string $field, array $formats) |
19
|
|
|
{ |
20
|
|
|
$this->setField($field); |
21
|
|
|
$this->setFormats($formats); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Set field. |
26
|
|
|
* |
27
|
|
|
* @return $this |
28
|
|
|
*/ |
29
|
|
|
public function setField(string $field): self |
30
|
|
|
{ |
31
|
|
|
return $this->setParam('field', $field); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Set field format. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N. |
36
|
|
|
* |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
|
|
public function setFormats(array $formats): self |
40
|
|
|
{ |
41
|
|
|
return $this->setParam('formats', $formats); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Set target_field. Default value @timestamp. |
46
|
|
|
* |
47
|
|
|
* @return $this |
48
|
|
|
*/ |
49
|
|
|
public function setTargetField(string $targetField): self |
50
|
|
|
{ |
51
|
|
|
return $this->setParam('target_field', $targetField); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set the timezone use when parsing the date. Default UTC. |
56
|
|
|
* |
57
|
|
|
* @return $this |
58
|
|
|
*/ |
59
|
|
|
public function setTimezone(string $timezone): self |
60
|
|
|
{ |
61
|
|
|
return $this->setParam('timezone', $timezone); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Set the locale to use when parsing the date. |
66
|
|
|
* |
67
|
|
|
* @return $this |
68
|
|
|
*/ |
69
|
|
|
public function setLocale(string $locale): self |
70
|
|
|
{ |
71
|
|
|
return $this->setParam('locale', $locale); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|