HTTPException.Class.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php // vim:set ts=4 sw=4 et:
  2. namespace Mall\Framework\SearchClient\Transport;
  3. /**
  4. * This file is part of the ElasticSearch PHP client
  5. *
  6. * (c) Raymond Julin <raymond.julin@gmail.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. class HTTPException extends \Exception {
  12. /**
  13. * Exception data
  14. * @var array
  15. */
  16. protected $data = array(
  17. 'payload' => null,
  18. 'protocol' => null,
  19. 'port' => null,
  20. 'host' => null,
  21. 'url' => null,
  22. 'method' => null,
  23. );
  24. /**
  25. * Setter
  26. * @param mixed $key
  27. * @param mixed $value
  28. */
  29. public function __set($key, $value) {
  30. if (array_key_exists($key, $this->data))
  31. $this->data[$key] = $value;
  32. }
  33. /**
  34. * Getter
  35. * @param mixed $key
  36. * @return mixed
  37. */
  38. public function __get($key) {
  39. if (array_key_exists($key, $this->data))
  40. return $this->data[$key];
  41. else
  42. return false;
  43. }
  44. /**
  45. * Rebuild CLI command using curl to further investigate the failure
  46. * @return string
  47. */
  48. public function getCLICommand() {
  49. $postData = json_encode($this->payload);
  50. $curlCall = "curl -X{$method} 'http://{$this->host}:{$this->port}$this->url' -d '$postData'";
  51. return $curlCall;
  52. }
  53. }