1<?php
2
3namespace Elasticsearch\Endpoints{% for class in namespace %}{{ loop.last ? ';' : '\\' ~ class|title  }}{%  endfor %}
4
5use Elasticsearch\Endpoints\AbstractEndpoint;
6use Elasticsearch\Common\Exceptions;
7
8/**
9 * Class {{ className|title|replace({'.': ""}) }}
10 *
11 * @category Elasticsearch
12 * @package Elasticsearch\Endpoints{% for class in namespace %}{{ loop.last ? '' : '\\' ~ class|title  }}{%  endfor %}
13
14 *
15 * @author   Zachary Tong <zach@elastic.co>
16 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache2
17 * @link     http://elastic.co
18 */
19
20class {{ className|title }} extends AbstractEndpoint
21{
22{% for part, info in data.url.parts %}
23{% if part != 'index' and part != 'type' and part != 'id' %}
24    // {{info.description }}
25    private ${{part}};
26{% endif %}
27{% endfor %}
28{% if data.body is not null %}
29    /**
30     * @param array $body
31     *
32     * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
33     * @return $this
34     */
35    public function setBody($body)
36    {
37        if (isset($body) !== true) {
38            return $this;
39        }
40
41        $this->body = $body;
42        return $this;
43    }
44
45
46
47{% endif %}
48{% for part, info in data.url.parts %}
49{% if part != 'index' and part != 'type' and part != 'id' %}
50    /**
51     * @param ${{part}}
52     *
53     * @return $this
54     */
55    public function set{{part|title|replace({'_': ""})}}(${{part}})
56    {
57        if (isset(${{part}}) !== true) {
58            return $this;
59        }
60{% if info.type == 'list' %}
61        if (is_array(${{part}}) === true) {
62            ${{part}} = implode(",", ${{part}});
63        }
64{% endif %}
65        $this->{{part}} = ${{part}};
66        return $this;
67    }
68
69{% endif %}
70{% endfor %}
71{% set exception = '' %}
72    /**
73{% for part, info in data.url.parts %}{% if info.required is not null %}{% set exception = ' * @throws \\Elasticsearch\\Common\\Exceptions\\BadMethodCallException
74    ' %}{% endif %}{% endfor %}
75    {% autoescape false %}{{ exception }}{% endautoescape %}
76 * @return string
77     */
78    protected function getURI()
79    {
80{% for part, info in data.url.parts %}
81{% if info.required == true %}
82        if (isset($this->{{ part }}) !== true) {
83            throw new Exceptions\RuntimeException(
84                '{{ part }} is required for {{ className }}'
85            );
86        }
87{% endif %}
88{% endfor %}
89{% for part, info in data.url.parts %}
90        ${{ part }} = $this->{{ part }};
91{% endfor %}
92        $uri   = "{{ data.url.default }}";
93{% set loopCounter = 0 %}
94{% for part, info in data.url.processed %}
95{% if info.count > 0 %}
96{% set counter = 0 %}
97{% if loopCounter != 0 %}
98    else{% endif %}if ({% for param in info.params %}{% if counter == 0 %}isset(${{ param }}) === true{% else %} && isset(${{ param }}) === true{% endif %}{% set counter = counter + 1 %}{% endfor %})
99        {
100            $uri = "{{ info.parsedPath }}";
101        }
102{% set loopCounter = 1 %}
103{% endif %}
104{% endfor %}
105
106        return $uri;
107    }
108
109
110    /**
111     * @return string[]
112     */
113    protected function getParamWhitelist()
114    {
115        return array(
116{% for param, options in data.url.params %}
117            '{{ param }}',
118{% endfor %}
119        );
120    }
121
122
123{% if data.body.required == true %}
124    /**
125     * @return array
126     * @throws \Elasticsearch\Common\Exceptions\RuntimeException
127     */
128    protected function getBody()
129    {
130        if (isset($this->body) !== true) {
131            throw new Exceptions\RuntimeException('Body is required for {{ className|title }}');
132        }
133        return $this->body;
134    }
135
136
137{% endif %}
138    /**
139     * @return string
140     */
141    protected function getMethod()
142    {
143{% if data.methods|length > 1 %}
144        //TODO Fix Me!
145        return '{{ data.methods|join(',') }}';
146{% else %}
147        return '{{ data.methods[0] }}';
148{% endif %}
149    }
150}