Create.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Elasticsearch\Endpoints\Indices;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class Create
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints\Indices
  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 Create extends AbstractEndpoint
  15. {
  16. /**
  17. * @param array|object $body
  18. *
  19. * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  20. * @return $this
  21. */
  22. public function setBody($body)
  23. {
  24. if (isset($body) !== true) {
  25. return $this;
  26. }
  27. $this->body = $body;
  28. return $this;
  29. }
  30. /**
  31. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  32. * @return string
  33. */
  34. public function getURI()
  35. {
  36. if (isset($this->index) !== true) {
  37. throw new Exceptions\RuntimeException(
  38. 'index is required for Create'
  39. );
  40. }
  41. $index = $this->index;
  42. $uri = "/$index";
  43. if (isset($index) === true) {
  44. $uri = "/$index";
  45. }
  46. return $uri;
  47. }
  48. /**
  49. * @return string[]
  50. */
  51. public function getParamWhitelist()
  52. {
  53. return array(
  54. 'timeout',
  55. 'master_timeout',
  56. 'update_all_types',
  57. 'wait_for_active_shards'
  58. );
  59. }
  60. /**
  61. * @return string
  62. */
  63. public function getMethod()
  64. {
  65. return 'PUT';
  66. }
  67. }