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