123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace Aws\Api;
- class DocModel
- {
-
- private $docs;
-
- public function __construct(array $docs)
- {
- if (!extension_loaded('tidy')) {
- throw new \RuntimeException('The "tidy" PHP extension is required.');
- }
- $this->docs = $docs;
- }
-
- public function toArray()
- {
- return $this->docs;
- }
-
- public function getServiceDocs()
- {
- return isset($this->docs['service']) ? $this->docs['service'] : null;
- }
-
- public function getOperationDocs($operation)
- {
- return isset($this->docs['operations'][$operation])
- ? $this->docs['operations'][$operation]
- : null;
- }
-
- public function getErrorDocs($error)
- {
- return isset($this->docs['shapes'][$error]['base'])
- ? $this->docs['shapes'][$error]['base']
- : null;
- }
-
- public function getShapeDocs($shapeName, $parentName, $ref)
- {
- if (!isset($this->docs['shapes'][$shapeName])) {
- return '';
- }
- $result = '';
- $d = $this->docs['shapes'][$shapeName];
- if (isset($d['refs']["{$parentName}\${$ref}"])) {
- $result = $d['refs']["{$parentName}\${$ref}"];
- } elseif (isset($d['base'])) {
- $result = $d['base'];
- }
- if (isset($d['append'])) {
- if (!isset($d['excludeAppend'])
- || !in_array($parentName, $d['excludeAppend'])
- ) {
- $result .= $d['append'];
- }
- }
- if (isset($d['appendOnly'])
- && in_array($parentName, $d['appendOnly']['shapes'])
- ) {
- $result .= $d['appendOnly']['message'];
- }
- return $this->clean($result);
- }
- private function clean($content)
- {
- if (!$content) {
- return '';
- }
- $tidy = new \tidy();
- $tidy->parseString($content, [
- 'indent' => true,
- 'doctype' => 'omit',
- 'output-html' => true,
- 'show-body-only' => true,
- 'drop-empty-paras' => true,
- 'clean' => true,
- 'drop-proprietary-attributes' => true,
- 'hide-comments' => true,
- 'logical-emphasis' => true
- ]);
- $tidy->cleanRepair();
- return (string) $content;
- }
- }
|