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