1<?php
2
3namespace Elastica\Processor;
4
5/**
6 * Elastica DateIndexName Processor.
7 *
8 * @author Federico Panini <fpanini@gmail.com>
9 *
10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/date-index-name-processor.html
11 */
12class DateIndexName extends AbstractProcessor
13{
14    const DEFAULT_DATE_FORMATS_VALUE = ['ISO8601'];
15    const DEFAULT_INDEX_NAME_FORMAT_VALUE = 'yyyy-MM-dd';
16    const DEFAULT_TIMEZONE_VALUE = 'UTC';
17    const DEFAULT_LOCALE_VALUE = 'ENGLISH';
18
19    /**
20     * DateIndexName constructor.
21     *
22     * @param string $field
23     * @param string $dateRounding
24     */
25    public function __construct(string $field, string $dateRounding)
26    {
27        $this->setField($field);
28        $this->setDateRounding($dateRounding);
29    }
30
31    /**
32     * Set field.
33     *
34     * @param string $field
35     *
36     * @return $this
37     */
38    public function setField(string $field): self
39    {
40        return $this->setParam('field', $field);
41    }
42
43    /**
44     * Set date_rounding. Valid values are: y (year), M (month), w (week), d (day), h (hour), m (minute) and s (second).
45     *
46     * @param string $dateRounding
47     *
48     * @return $this
49     */
50    public function setDateRounding(string $dateRounding): self
51    {
52        return $this->setParam('date_rounding', $dateRounding);
53    }
54
55    /**
56     * Set field formats. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N.
57     *
58     * @param array $formats
59     *
60     * @return $this
61     */
62    public function setDateFormats(array $formats): self
63    {
64        return $this->setParam('date_formats', $formats);
65    }
66
67    /**
68     * Set index_prefix_name.
69     *
70     * @param string $indexPrefixName
71     *
72     * @return $this
73     */
74    public function setIndexNamePrefix(string $indexPrefixName): self
75    {
76        return $this->setParam('index_name_prefix', $indexPrefixName);
77    }
78
79    /**
80     * Set format to be used when printing parsed date. An valid Joda pattern is expected here. Default yyyy-MM-dd.
81     *
82     * @param string $indexNameFormat
83     *
84     * @return $this
85     */
86    public function setIndexNameFormat(string $indexNameFormat): self
87    {
88        return $this->setParam('index_name_format', $indexNameFormat);
89    }
90
91    /**
92     * Set the timezone use when parsing the date. Default UTC.
93     *
94     * @param string $timezone
95     *
96     * @return $this
97     */
98    public function setTimezone(string $timezone): self
99    {
100        return $this->setParam('timezone', $timezone);
101    }
102
103    /**
104     * Set the locale to use when parsing the date.
105     *
106     * @param string $locale
107     *
108     * @return $this
109     */
110    public function setLocale(string $locale): self
111    {
112        return $this->setParam('locale', $locale);
113    }
114}
115