PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.4
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.4
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / MCP / Support / Schemas.php

Schemas.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.4, at inc/MCP/Support/Schemas.php

169 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 LearnPress\MCP\Support;
4
5 defined( 'ABSPATH' ) || exit;
6
7 /**
8 * Shared JSON schema builders for Phase 2 MCP tools.
9 *
10 * Keeps every input schema strict (`additionalProperties=false`) and reuses
11 * common field shapes so the per-domain schema providers stay small.
12 */
13 class Schemas {
14
15 /**
16 * Allowed post statuses for Phase 2 write tools.
17 *
18 * @return string[]
19 */
20 public static function allowed_statuses(): array {
21 return array( 'draft', 'publish', 'pending' );
22 }
23
24 /**
25 * Build a strict object schema.
26 *
27 * @param array $properties Property schemas keyed by name.
28 * @param string[] $required Required property names.
29 *
30 * @return array
31 */
32 public static function object( array $properties, array $required = array() ): array {
33 $schema = array(
34 'type' => 'object',
35 'additionalProperties' => false,
36 'properties' => $properties,
37 );
38
39 if ( ! empty( $required ) ) {
40 $schema['required'] = array_values( $required );
41 }
42
43 return $schema;
44 }
45
46 /**
47 * Positive integer ID schema.
48 *
49 * @return array
50 */
51 public static function id(): array {
52 return array(
53 'type' => 'integer',
54 'minimum' => 1,
55 );
56 }
57
58 /**
59 * Strict object schema requiring a single positive integer ID field.
60 *
61 * @param string $id Field name (e.g. "course_id").
62 *
63 * @return array
64 */
65 public static function required_id( string $id ): array {
66 return self::object( array( $id => self::id() ), array( $id ) );
67 }
68
69 /**
70 * Post status enum schema restricted to the Phase 2 allowlist.
71 *
72 * @return array
73 */
74 public static function status(): array {
75 return array(
76 'type' => 'string',
77 'enum' => self::allowed_statuses(),
78 );
79 }
80
81 /**
82 * String schema.
83 *
84 * @return array
85 */
86 public static function string(): array {
87 return array( 'type' => 'string' );
88 }
89
90 /**
91 * Boolean schema.
92 *
93 * @return array
94 */
95 public static function boolean(): array {
96 return array( 'type' => 'boolean' );
97 }
98
99 /**
100 * Number schema with optional minimum.
101 *
102 * @param float|null $minimum Optional minimum value.
103 *
104 * @return array
105 */
106 public static function number( ?float $minimum = null ): array {
107 $schema = array( 'type' => 'number' );
108 if ( null !== $minimum ) {
109 $schema['minimum'] = $minimum;
110 }
111
112 return $schema;
113 }
114
115 /**
116 * Integer schema with optional minimum.
117 *
118 * @param int|null $minimum Optional minimum value.
119 *
120 * @return array
121 */
122 public static function integer( ?int $minimum = null ): array {
123 $schema = array( 'type' => 'integer' );
124 if ( null !== $minimum ) {
125 $schema['minimum'] = $minimum;
126 }
127
128 return $schema;
129 }
130
131 /**
132 * Array-of-positive-IDs schema.
133 *
134 * @return array
135 */
136 public static function id_array(): array {
137 return array(
138 'type' => 'array',
139 'items' => self::id(),
140 );
141 }
142
143 /**
144 * Array-of-strings schema.
145 *
146 * @return array
147 */
148 public static function string_array(): array {
149 return array(
150 'type' => 'array',
151 'items' => self::string(),
152 );
153 }
154
155 /**
156 * Strict object output wrapper schema, e.g. { "course": { ... } }.
157 *
158 * @param string $key Wrapper key.
159 *
160 * @return array
161 */
162 public static function object_output( string $key ): array {
163 return self::object(
164 array( $key => array( 'type' => 'object' ) ),
165 array( $key )
166 );
167 }
168 }
169