Result.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Aws;
  3. use JmesPath\Env as JmesPath;
  4. /**
  5. * AWS result.
  6. */
  7. class Result implements ResultInterface
  8. {
  9. use HasDataTrait;
  10. public function __construct(array $data = [])
  11. {
  12. $this->data = $data;
  13. }
  14. public function hasKey($name)
  15. {
  16. return isset($this->data[$name]);
  17. }
  18. public function get($key)
  19. {
  20. return $this[$key];
  21. }
  22. public function search($expression)
  23. {
  24. return JmesPath::search($expression, $this->toArray());
  25. }
  26. public function __toString()
  27. {
  28. $jsonData = json_encode($this->toArray(), JSON_PRETTY_PRINT);
  29. return <<<EOT
  30. Model Data
  31. ----------
  32. Data can be retrieved from the model object using the get() method of the
  33. model (e.g., `\$result->get(\$key)`) or "accessing the result like an
  34. associative array (e.g. `\$result['key']`). You can also execute JMESPath
  35. expressions on the result data using the search() method.
  36. {$jsonData}
  37. EOT;
  38. }
  39. /**
  40. * @deprecated
  41. */
  42. public function getPath($path)
  43. {
  44. return $this->search(str_replace('/', '.', $path));
  45. }
  46. }