PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / Api / DocModel.php
transferito / vendor / aws / aws-sdk-php / src / Api Last commit date
ErrorParser 11 months ago Parser 11 months ago Serializer 11 months ago AbstractModel.php 11 months ago ApiProvider.php 11 months ago DateTimeResult.php 11 months ago DocModel.php 11 months ago ListShape.php 11 months ago MapShape.php 11 months ago Operation.php 11 months ago Service.php 11 months ago Shape.php 11 months ago ShapeMap.php 11 months ago StructureShape.php 11 months ago TimestampShape.php 11 months ago Validator.php 11 months ago
DocModel.php
139 lines
1 <?php
2 namespace Aws\Api;
3
4 /**
5 * Encapsulates the documentation strings for a given service-version and
6 * provides methods for extracting the desired parts related to a service,
7 * operation, error, or shape (i.e., parameter).
8 */
9 class DocModel
10 {
11 /** @var array */
12 private $docs;
13
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
25 $this->docs = $docs;
26 }
27
28 /**
29 * Convert the doc model to an array.
30 *
31 * @return array
32 */
33 public function toArray()
34 {
35 return $this->docs;
36 }
37
38 /**
39 * Retrieves documentation about the service.
40 *
41 * @return null|string
42 */
43 public function getServiceDocs()
44 {
45 return isset($this->docs['service']) ? $this->docs['service'] : null;
46 }
47
48 /**
49 * Retrieves documentation about an operation.
50 *
51 * @param string $operation Name of the operation
52 *
53 * @return null|string
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 * Retrieves documentation about an error.
64 *
65 * @param string $error Name of the error
66 *
67 * @return null|string
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 * Retrieves documentation about a shape, specific to the context.
78 *
79 * @param string $shapeName Name of the shape.
80 * @param string $parentName Name of the parent/context shape.
81 * @param string $ref Name used by the context to reference the shape.
82 *
83 * @return null|string
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 private function clean($content)
117 {
118 if (!$content) {
119 return '';
120 }
121
122 $tidy = new \tidy();
123 $tidy->parseString($content, [
124 'indent' => true,
125 'doctype' => 'omit',
126 'output-html' => true,
127 'show-body-only' => true,
128 'drop-empty-paras' => true,
129 'drop-font-tags' => true,
130 'drop-proprietary-attributes' => true,
131 'hide-comments' => true,
132 'logical-emphasis' => true
133 ]);
134 $tidy->cleanRepair();
135
136 return (string) $content;
137 }
138 }
139