| 1 |
<?php |
| 2 |
namespace Aws\Api; |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class DocModel |
| 10 |
{ |
| 11 |
|
| 12 |
private $docs; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public function __construct(array $docs) |
| 20 |
{ |
| 21 |
if (!extension_loaded('tidy')) { |
| 22 |
throw new \RuntimeException('The "tidy" PHP extension is required.'); |
| 23 |
} |
| 24 |
|
| 25 |
$this->docs = $docs; |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function toArray() |
| 34 |
{ |
| 35 |
return $this->docs; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function getServiceDocs() |
| 44 |
{ |
| 45 |
return isset($this->docs['service']) ? $this->docs['service'] : null; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function getOperationDocs($operation) |
| 56 |
{ |
| 57 |
return isset($this->docs['operations'][$operation]) |
| 58 |
? $this->docs['operations'][$operation] |
| 59 |
: null; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function getErrorDocs($error) |
| 70 |
{ |
| 71 |
return isset($this->docs['shapes'][$error]['base']) |
| 72 |
? $this->docs['shapes'][$error]['base'] |
| 73 |
: null; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public function getShapeDocs($shapeName, $parentName, $ref) |
| 86 |
{ |
| 87 |
if (!isset($this->docs['shapes'][$shapeName])) { |
| 88 |
return ''; |
| 89 |
} |
| 90 |
|
| 91 |
$result = ''; |
| 92 |
$d = $this->docs['shapes'][$shapeName]; |
| 93 |
if (isset($d['refs']["{$parentName}\${$ref}"])) { |
| 94 |
$result = $d['refs']["{$parentName}\${$ref}"]; |
| 95 |
} elseif (isset($d['base'])) { |
| 96 |
$result = $d['base']; |
| 97 |
} |
| 98 |
|
| 99 |
if (isset($d['append'])) { |
| 100 |
if (!isset($d['excludeAppend']) |
| 101 |
|| !in_array($parentName, $d['excludeAppend']) |
| 102 |
) { |
| 103 |
$result .= $d['append']; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
if (isset($d['appendOnly']) |
| 108 |
&& in_array($parentName, $d['appendOnly']['shapes']) |
| 109 |
) { |
| 110 |
$result .= $d['appendOnly']['message']; |
| 111 |
} |
| 112 |
|
| 113 |
return $this->clean($result); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
private function clean($content) |
| 118 |
{ |
| 119 |
if (!$content) { |
| 120 |
return ''; |
| 121 |
} |
| 122 |
|
| 123 |
$tidy = new \tidy(); |
| 124 |
$tidy->parseString($content, [ |
| 125 |
'indent' => true, |
| 126 |
'doctype' => 'omit', |
| 127 |
'output-html' => true, |
| 128 |
'show-body-only' => true, |
| 129 |
'drop-empty-paras' => true, |
| 130 |
'clean' => true, |
| 131 |
'drop-proprietary-attributes' => true, |
| 132 |
'hide-comments' => true, |
| 133 |
'logical-emphasis' => true |
| 134 |
]); |
| 135 |
$tidy->cleanRepair(); |
| 136 |
|
| 137 |
return (string) $content; |
| 138 |
} |
| 139 |
} |