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