Put.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Elasticsearch\Endpoints\Indices\Alias;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class Put
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints\Indices\Alias
  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 alias to be created or updated
  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. if (isset($this->index) !== true) {
  57. throw new Exceptions\RuntimeException(
  58. 'index is required for Put'
  59. );
  60. }
  61. $index = $this->index;
  62. $name = $this->name;
  63. $uri = "/$index/_alias/$name";
  64. return $uri;
  65. }
  66. /**
  67. * @return string[]
  68. */
  69. public function getParamWhitelist()
  70. {
  71. return array(
  72. 'timeout',
  73. 'master_timeout',
  74. );
  75. }
  76. /**
  77. * @return string
  78. */
  79. public function getMethod()
  80. {
  81. return 'PUT';
  82. }
  83. }