1<?php 2 3namespace Elastica\Index; 4 5use Elastica\Index as BaseIndex; 6use Elastica\Response; 7use Elasticsearch\Endpoints\Indices\Recovery as RecoveryEndpoint; 8 9/** 10 * Elastica index recovery object. 11 * 12 * @author Federico Panini <fpanini@gmail.com> 13 * 14 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html 15 */ 16class Recovery 17{ 18 /** 19 * Response. 20 * 21 * @var Response Response object 22 */ 23 protected $_response; 24 25 /** 26 * Recovery info. 27 * 28 * @var array Recovery info 29 */ 30 protected $_data = []; 31 32 /** 33 * Index. 34 * 35 * @var BaseIndex Index object 36 */ 37 protected $_index; 38 39 /** 40 * Construct. 41 * 42 * @param BaseIndex $index Index object 43 */ 44 public function __construct(BaseIndex $index) 45 { 46 $this->_index = $index; 47 $this->refresh(); 48 } 49 50 /** 51 * Returns the index object. 52 * 53 * @return BaseIndex Index object 54 */ 55 public function getIndex(): BaseIndex 56 { 57 return $this->_index; 58 } 59 60 /** 61 * Returns response object. 62 * 63 * @return Response Response object 64 */ 65 public function getResponse(): Response 66 { 67 return $this->_response; 68 } 69 70 /** 71 * Returns the raw recovery info. 72 * 73 * @return array Recovery info 74 */ 75 public function getData(): array 76 { 77 return $this->_data; 78 } 79 80 /** 81 * Retrieve the Recovery data. 82 * 83 * @return $this 84 */ 85 public function refresh(): self 86 { 87 $this->_data = $this->getRecoveryData(); 88 89 return $this; 90 } 91 92 /** 93 * @return array 94 */ 95 protected function getRecoveryData() 96 { 97 $endpoint = new RecoveryEndpoint(); 98 99 $this->_response = $this->getIndex()->requestEndpoint($endpoint); 100 101 return $this->getResponse()->getData(); 102 } 103} 104