-
Notifications
You must be signed in to change notification settings - Fork 965
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3cac7d
commit 8341c4c
Showing
2 changed files
with
93 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,153 +2,149 @@ | |
namespace Elasticsearch\Endpoints{% for class in namespace %}{{ loop.last ? ';' : '\\' ~ class|title }}{% endfor %} | ||
use Elasticsearch\Endpoints\AbstractEndpoint; | ||
use Elasticsearch\Common\Exceptions; | ||
/** | ||
* Class {{ className|title }} | ||
* Class {{ className|title|replace({'.': ""}) }} | ||
* | ||
* @category Elasticsearch | ||
* @package Elasticsearch\Endpoints{% for class in namespace %}{{ loop.last ? '' : '\\' ~ class|title }}{% endfor %} | ||
* | ||
* @author Zachary Tong <[email protected]> | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 | ||
* @link http://elasticsearch.org | ||
*/ | ||
* @author Zachary Tong <[email protected]> | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 | ||
* @link http://elastic.co | ||
*/ | ||
class {{ className|title }} extends AbstractEndpoint | ||
{ | ||
{% for part, info in data.url.parts %} | ||
{% if part != 'index' and part != 'type' and part != 'id' %} | ||
// {{info.description }} | ||
private ${{part}}; | ||
{% endif %} | ||
{% if part != 'index' and part != 'type' and part != 'id' %} | ||
// {{info.description }} | ||
private ${{part}}; | ||
{% endif %} | ||
{% endfor %} | ||
{% if data.body is not null %} | ||
/** | ||
* @param array $body | ||
* | ||
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException | ||
* @return $this | ||
*/ | ||
* @param array $body | ||
* | ||
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException | ||
* @return $this | ||
*/ | ||
public function setBody($body) | ||
{ | ||
if (isset($body) !== true) { | ||
return $this; | ||
} | ||
if (isset($body) !== true) { | ||
return $this; | ||
} | ||
if (is_array($body) !== true) { | ||
throw new Exceptions\InvalidArgumentException( | ||
'Body must be an array' | ||
); | ||
} | ||
$this->body = $body; | ||
return $this; | ||
$this->body = $body; | ||
return $this; | ||
} | ||
{% endif %} | ||
{% for part, info in data.url.parts %} | ||
{% if part != 'index' and part != 'type' and part != 'id' %} | ||
/** | ||
* @param ${{part}} | ||
* | ||
* @return $this | ||
*/ | ||
public function set{{part|title}}(${{part}}) | ||
{ | ||
{% if part != 'index' and part != 'type' and part != 'id' %} | ||
/** | ||
* @param ${{part}} | ||
* | ||
* @return $this | ||
*/ | ||
public function set{{part|title|replace({'_': ""})}}(${{part}}) | ||
{ | ||
if (isset(${{part}}) !== true) { | ||
return $this; | ||
return $this; | ||
} | ||
{% if info.type == 'list' %} | ||
if (is_array(${{part}}) === true) { | ||
${{part}} = implode(",", ${{part}}); | ||
} | ||
{% endif %} | ||
$this->{{part}} = ${{part}}; | ||
return $this; | ||
} | ||
} | ||
{% endif %} | ||
{% endif %} | ||
{% endfor %} | ||
{% set exception = '' %} | ||
/** | ||
{% for part, info in data.url.parts %} | ||
{% if info.required is not null %} | ||
{% set exception = ' * @throws \\Elasticsearch\\Common\\Exceptions\\BadMethodCallException | ||
' %} | ||
{% endif %} | ||
{% endfor %}{% autoescape false %}{{ exception }}{% endautoescape %} | ||
* @return string | ||
*/ | ||
protected function getURI() | ||
{ | ||
/** | ||
{% for part, info in data.url.parts %}{% if info.required is not null %}{% set exception = ' * @throws \\Elasticsearch\\Common\\Exceptions\\BadMethodCallException | ||
' %}{% endif %}{% endfor %} | ||
{% autoescape false %}{{ exception }}{% endautoescape %} | ||
* @return string | ||
*/ | ||
protected function getURI() | ||
{ | ||
{% for part, info in data.url.parts %} | ||
{% if info.required == true %} | ||
{% if info.required == true %} | ||
if (isset($this->{{ part }}) !== true) { | ||
throw new Exceptions\RuntimeException( | ||
'{{ part }} is required for {{ className }}' | ||
); | ||
throw new Exceptions\RuntimeException( | ||
'{{ part }} is required for {{ className }}' | ||
); | ||
} | ||
{% endif %} | ||
{% endif %} | ||
{% endfor %} | ||
{% for part, info in data.url.parts %} | ||
${{ part }} = $this->{{ part }}; | ||
${{ part }} = $this->{{ part }}; | ||
{% endfor %} | ||
$uri = "{{ data.url.default }}"; | ||
$uri = "{{ data.url.default }}"; | ||
{% set loopCounter = 0 %} | ||
{% for part, info in data.url.processed %} | ||
{% if info.count > 0 %} | ||
{% set counter = 0 %} | ||
{% 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 %}) { | ||
$uri = "{{ info.parsedPath }}"; | ||
{% if info.count > 0 %} | ||
{% set counter = 0 %} | ||
{% if loopCounter != 0 %} | ||
else{% endif %}if ({% for param in info.params %}{% if counter == 0 %}isset(${{ param }}) === true{% else %} && isset(${{ param }}) === true{% endif %}{% set counter = counter + 1 %}{% endfor %}) | ||
{ | ||
$uri = "{{ info.parsedPath }}"; | ||
} | ||
{% endif %} | ||
{% set loopCounter = 1 %} | ||
{% endif %} | ||
{% endfor %} | ||
return $uri; | ||
} | ||
return $uri; | ||
} | ||
/** | ||
* @return string[] | ||
*/ | ||
protected function getParamWhitelist() | ||
{ | ||
return array( | ||
/** | ||
* @return string[] | ||
*/ | ||
protected function getParamWhitelist() | ||
{ | ||
return array( | ||
{% for param, options in data.url.params %} | ||
'{{ param }}', | ||
'{{ param }}', | ||
{% endfor %} | ||
); | ||
} | ||
); | ||
} | ||
{% if data.body.required == true %} | ||
/** | ||
* @return array | ||
* @throws \Elasticsearch\Common\Exceptions\RuntimeException | ||
*/ | ||
* @return array | ||
* @throws \Elasticsearch\Common\Exceptions\RuntimeException | ||
*/ | ||
protected function getBody() | ||
{ | ||
if (isset($this->body) !== true) { | ||
throw new Exceptions\RuntimeException('Body is required for Put'); | ||
} | ||
return $this->body; | ||
if (isset($this->body) !== true) { | ||
throw new Exceptions\RuntimeException('Body is required for {{ className|title }}'); | ||
} | ||
return $this->body; | ||
} | ||
{% endif %} | ||
/** | ||
* @return string | ||
*/ | ||
protected function getMethod() | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
protected function getMethod() | ||
{ | ||
{% if data.methods|length > 1 %} | ||
//TODO Fix Me! | ||
return '{{ data.methods|join(',') }}'; | ||
//TODO Fix Me! | ||
return '{{ data.methods|join(',') }}'; | ||
{% else %} | ||
return '{{ data.methods[0] }}'; | ||
return '{{ data.methods[0] }}'; | ||
{% endif %} | ||
} | ||
} | ||
} |