1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65:
<?php
namespace Guzzle\Service\Resource;
use Guzzle\Common\Collection;
use Guzzle\Service\Description\Parameter;
class Model extends Collection
{
protected $structure;
public function __construct(array $data = array(), Parameter $structure = null)
{
$this->data = $data;
$this->structure = $structure;
}
public function getStructure()
{
return $this->structure ?: new Parameter();
}
public function __toString()
{
$output = 'Debug output of ';
if ($this->structure) {
$output .= $this->structure->getName() . ' ';
}
$output .= 'model';
$output = str_repeat('=', strlen($output)) . "\n" . $output . "\n" . str_repeat('=', strlen($output)) . "\n\n";
$output .= "Model data\n-----------\n\n";
$output .= "This data can be retrieved from the model object using the get() method of the model "
. "(e.g. \$model->get(\$key)) or accessing the model like an associative array (e.g. \$model['key']).\n\n";
$lines = array_slice(explode("\n", trim(print_r($this->toArray(), true))), 2, -1);
$output .= implode("\n", $lines);
if ($this->structure) {
$output .= "\n\nModel structure\n---------------\n\n";
$output .= "The following JSON document defines how the model was parsed from an HTTP response into the "
. "associative array structure you see above.\n\n";
$output .= ' ' . json_encode($this->structure->toArray()) . "\n\n";
}
return $output . "\n";
}
}