PluginProbe
Media Cloud Sync / 1.2.13
Media Cloud Sync v1.2.13
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / DocModel.php

DocModel.php in Media Cloud Sync 1.2.13, at includes/sdk/s3/Aws/Api/DocModel.php

108 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Api;
4
5 /**
6 * Encapsulates the documentation strings for a given service-version and
7 * provides methods for extracting the desired parts related to a service,
8 * operation, error, or shape (i.e., parameter).
9 */
10 class DocModel
11 {
12 /** @var array */
13 private $docs;
14 /**
15 * @param array $docs
16 *
17 * @throws \RuntimeException
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 $this->docs = $docs;
25 }
26 /**
27 * Convert the doc model to an array.
28 *
29 * @return array
30 */
31 public function toArray()
32 {
33 return $this->docs;
34 }
35 /**
36 * Retrieves documentation about the service.
37 *
38 * @return null|string
39 */
40 public function getServiceDocs()
41 {
42 return isset($this->docs['service']) ? $this->docs['service'] : null;
43 }
44 /**
45 * Retrieves documentation about an operation.
46 *
47 * @param string $operation Name of the operation
48 *
49 * @return null|string
50 */
51 public function getOperationDocs($operation)
52 {
53 return isset($this->docs['operations'][$operation]) ? $this->docs['operations'][$operation] : null;
54 }
55 /**
56 * Retrieves documentation about an error.
57 *
58 * @param string $error Name of the error
59 *
60 * @return null|string
61 */
62 public function getErrorDocs($error)
63 {
64 return isset($this->docs['shapes'][$error]['base']) ? $this->docs['shapes'][$error]['base'] : null;
65 }
66 /**
67 * Retrieves documentation about a shape, specific to the context.
68 *
69 * @param string $shapeName Name of the shape.
70 * @param string $parentName Name of the parent/context shape.
71 * @param string $ref Name used by the context to reference the shape.
72 *
73 * @return null|string
74 */
75 public function getShapeDocs($shapeName, $parentName, $ref)
76 {
77 if (!isset($this->docs['shapes'][$shapeName])) {
78 return '';
79 }
80 $result = '';
81 $d = $this->docs['shapes'][$shapeName];
82 if (isset($d['refs']["{$parentName}\${$ref}"])) {
83 $result = $d['refs']["{$parentName}\${$ref}"];
84 } elseif (isset($d['base'])) {
85 $result = $d['base'];
86 }
87 if (isset($d['append'])) {
88 if (!isset($d['excludeAppend']) || !\in_array($parentName, $d['excludeAppend'])) {
89 $result .= $d['append'];
90 }
91 }
92 if (isset($d['appendOnly']) && \in_array($parentName, $d['appendOnly']['shapes'])) {
93 $result .= $d['appendOnly']['message'];
94 }
95 return $this->clean($result);
96 }
97 private function clean($content)
98 {
99 if (!$content) {
100 return '';
101 }
102 $tidy = new \tidy();
103 $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]);
104 $tidy->cleanRepair();
105 return (string) $content;
106 }
107 }
108