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
|
|
|
/** |
19
|
|
|
* Date constructor. |
20
|
|
|
*/ |
21
|
|
|
public function __construct(string $field, array $formats) |
22
|
|
|
{ |
23
|
|
|
$this->setField($field); |
24
|
|
|
$this->setFormats($formats); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Set field. |
29
|
|
|
* |
30
|
|
|
* @return $this |
31
|
|
|
*/ |
32
|
|
|
public function setField(string $field): self |
33
|
|
|
{ |
34
|
|
|
return $this->setParam('field', $field); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Set field format. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N. |
39
|
|
|
* |
40
|
|
|
* @return $this |
41
|
|
|
*/ |
42
|
|
|
public function setFormats(array $formats): self |
43
|
|
|
{ |
44
|
|
|
return $this->setParam('formats', $formats); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Set target_field. Default value @timestamp. |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function setTargetField(string $targetField): self |
53
|
|
|
{ |
54
|
|
|
return $this->setParam('target_field', $targetField); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Set the timezone use when parsing the date. Default UTC. |
59
|
|
|
* |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function setTimezone(string $timezone): self |
63
|
|
|
{ |
64
|
|
|
return $this->setParam('timezone', $timezone); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Set the locale to use when parsing the date. |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function setLocale(string $locale): self |
73
|
|
|
{ |
74
|
|
|
return $this->setParam('locale', $locale); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|