Stats.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace Elastica\Index;
  3. use Elastica\Index as BaseIndex;
  4. /**
  5. * Elastica index stats object.
  6. *
  7. * @author Nicolas Ruflin <spam@ruflin.com>
  8. *
  9. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
  10. */
  11. class Stats
  12. {
  13. /**
  14. * Response.
  15. *
  16. * @var \Elastica\Response Response object
  17. */
  18. protected $_response;
  19. /**
  20. * Stats info.
  21. *
  22. * @var array Stats info
  23. */
  24. protected $_data = [];
  25. /**
  26. * Index.
  27. *
  28. * @var \Elastica\Index Index object
  29. */
  30. protected $_index;
  31. /**
  32. * Construct.
  33. *
  34. * @param \Elastica\Index $index Index object
  35. */
  36. public function __construct(BaseIndex $index)
  37. {
  38. $this->_index = $index;
  39. $this->refresh();
  40. }
  41. /**
  42. * Returns the raw stats info.
  43. *
  44. * @return array Stats info
  45. */
  46. public function getData()
  47. {
  48. return $this->_data;
  49. }
  50. /**
  51. * Returns the entry in the data array based on the params.
  52. * Various params possible.
  53. *
  54. * @return mixed Data array entry or null if not found
  55. */
  56. public function get()
  57. {
  58. $data = $this->getData();
  59. foreach (func_get_args() as $arg) {
  60. if (isset($data[$arg])) {
  61. $data = $data[$arg];
  62. } else {
  63. return;
  64. }
  65. }
  66. return $data;
  67. }
  68. /**
  69. * Returns the index object.
  70. *
  71. * @return \Elastica\Index Index object
  72. */
  73. public function getIndex()
  74. {
  75. return $this->_index;
  76. }
  77. /**
  78. * Returns response object.
  79. *
  80. * @return \Elastica\Response Response object
  81. */
  82. public function getResponse()
  83. {
  84. return $this->_response;
  85. }
  86. /**
  87. * Reloads all status data of this object.
  88. */
  89. public function refresh()
  90. {
  91. $this->_response = $this->getIndex()->requestEndpoint(new \Elasticsearch\Endpoints\Indices\Stats());
  92. $this->_data = $this->getResponse()->getData();
  93. }
  94. }