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