Create.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace Elasticsearch\Endpoints\Snapshot;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class Create
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints\Snapshot
  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. // A repository name
  17. private $repository;
  18. // A snapshot name
  19. private $snapshot;
  20. /**
  21. * @param array $body
  22. *
  23. * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  24. * @return $this
  25. */
  26. public function setBody($body)
  27. {
  28. if (isset($body) !== true) {
  29. return $this;
  30. }
  31. $this->body = $body;
  32. return $this;
  33. }
  34. /**
  35. * @param $repository
  36. *
  37. * @return $this
  38. */
  39. public function setRepository($repository)
  40. {
  41. if (isset($repository) !== true) {
  42. return $this;
  43. }
  44. $this->repository = $repository;
  45. return $this;
  46. }
  47. /**
  48. * @param $snapshot
  49. *
  50. * @return $this
  51. */
  52. public function setSnapshot($snapshot)
  53. {
  54. if (isset($snapshot) !== true) {
  55. return $this;
  56. }
  57. $this->snapshot = $snapshot;
  58. return $this;
  59. }
  60. /**
  61. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  62. * @return string
  63. */
  64. public function getURI()
  65. {
  66. if (isset($this->repository) !== true) {
  67. throw new Exceptions\RuntimeException(
  68. 'repository is required for Create'
  69. );
  70. }
  71. if (isset($this->snapshot) !== true) {
  72. throw new Exceptions\RuntimeException(
  73. 'snapshot is required for Create'
  74. );
  75. }
  76. $repository = $this->repository;
  77. $snapshot = $this->snapshot;
  78. $uri = "/_snapshot/$repository/$snapshot";
  79. if (isset($repository) === true && isset($snapshot) === true) {
  80. $uri = "/_snapshot/$repository/$snapshot";
  81. }
  82. return $uri;
  83. }
  84. /**
  85. * @return string[]
  86. */
  87. public function getParamWhitelist()
  88. {
  89. return array(
  90. 'master_timeout',
  91. 'wait_for_completion',
  92. );
  93. }
  94. /**
  95. * @return string
  96. */
  97. public function getMethod()
  98. {
  99. return 'PUT';
  100. }
  101. }