Put.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Elasticsearch\Endpoints\Indices\Template;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class Put
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints\Indices\Template
  10. * @author Zachary Tong <zach@elastic.co>
  11. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  12. * @link http://elastic.co
  13. */
  14. class Put extends AbstractEndpoint
  15. {
  16. // The name of the template
  17. private $name;
  18. /**
  19. * @param array $body
  20. *
  21. * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  22. * @return $this
  23. */
  24. public function setBody($body)
  25. {
  26. if (isset($body) !== true) {
  27. return $this;
  28. }
  29. $this->body = $body;
  30. return $this;
  31. }
  32. /**
  33. * @param $name
  34. *
  35. * @return $this
  36. */
  37. public function setName($name)
  38. {
  39. if (isset($name) !== true) {
  40. return $this;
  41. }
  42. $this->name = $name;
  43. return $this;
  44. }
  45. /**
  46. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  47. * @return string
  48. */
  49. public function getURI()
  50. {
  51. if (isset($this->name) !== true) {
  52. throw new Exceptions\RuntimeException(
  53. 'name is required for Put'
  54. );
  55. }
  56. $name = $this->name;
  57. $uri = "/_template/$name";
  58. if (isset($name) === true) {
  59. $uri = "/_template/$name";
  60. }
  61. return $uri;
  62. }
  63. /**
  64. * @return string[]
  65. */
  66. public function getParamWhitelist()
  67. {
  68. return array(
  69. 'order',
  70. 'timeout',
  71. 'master_timeout',
  72. 'flat_settings',
  73. 'create'
  74. );
  75. }
  76. /**
  77. * @return array
  78. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  79. */
  80. public function getBody()
  81. {
  82. if (isset($this->body) !== true) {
  83. throw new Exceptions\RuntimeException('Body is required for Put Template');
  84. }
  85. return $this->body;
  86. }
  87. /**
  88. * @return string
  89. */
  90. public function getMethod()
  91. {
  92. return 'PUT';
  93. }
  94. }