Create.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Elasticsearch\Endpoints\Snapshot\Repository;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class Create
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints\Snapshot\Repository
  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. /**
  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 $repository
  34. *
  35. * @return $this
  36. */
  37. public function setRepository($repository)
  38. {
  39. if (isset($repository) !== true) {
  40. return $this;
  41. }
  42. $this->repository = $repository;
  43. return $this;
  44. }
  45. /**
  46. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  47. * @return string
  48. */
  49. public function getURI()
  50. {
  51. if (isset($this->repository) !== true) {
  52. throw new Exceptions\RuntimeException(
  53. 'repository is required for Create'
  54. );
  55. }
  56. $repository = $this->repository;
  57. $uri = "/_snapshot/$repository";
  58. if (isset($repository) === true) {
  59. $uri = "/_snapshot/$repository";
  60. }
  61. return $uri;
  62. }
  63. /**
  64. * @return string[]
  65. */
  66. public function getParamWhitelist()
  67. {
  68. return array(
  69. 'master_timeout',
  70. 'timeout',
  71. 'verify'
  72. );
  73. }
  74. /**
  75. * @return array
  76. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  77. */
  78. public function getBody()
  79. {
  80. if (isset($this->body) !== true) {
  81. throw new Exceptions\RuntimeException('Body is required for Create Repository');
  82. }
  83. return $this->body;
  84. }
  85. /**
  86. * @return string
  87. */
  88. public function getMethod()
  89. {
  90. return 'PUT';
  91. }
  92. }