PluginProbe
Polylang / 3.7
Polylang v3.7
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / Options / Primitive / Abstract_List.php

Abstract_List.php in Polylang 3.7, at include/Options/Primitive/Abstract_List.php

81 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 namespace WP_Syntex\Polylang\Options\Primitive;
7
8 use WP_Syntex\Polylang\Options\Abstract_Option;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Class defining single list option, default value type to mixed.
14 *
15 * @since 3.7
16 *
17 * @phpstan-import-type SchemaType from Abstract_Option
18 */
19 abstract class Abstract_List extends Abstract_Option {
20 /**
21 * Prepares a value before validation.
22 * Allows to receive a string-keyed array but returns an integer-keyed array.
23 *
24 * @since 3.7
25 *
26 * @param mixed $value Value to format.
27 * @return mixed
28 */
29 protected function prepare( $value ) {
30 if ( is_array( $value ) ) {
31 return array_values( $value );
32 }
33 return $value;
34 }
35
36 /**
37 * Returns the JSON schema value type for the list items.
38 * Possible values are `'string'`, `'null'`, `'number'` (float), `'integer'`, `'boolean'`,
39 * `'array'` (array with integer keys), and `'object'` (array with string keys).
40 *
41 * @since 3.7
42 * @see https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#primitive-types
43 *
44 * @return string
45 *
46 * @phpstan-return SchemaType
47 */
48 protected function get_type(): string {
49 return 'string';
50 }
51
52 /**
53 * Returns the default value.
54 *
55 * @since 3.7
56 *
57 * @return array
58 */
59 protected function get_default() {
60 return array();
61 }
62
63 /**
64 * Returns the JSON schema part specific to this option.
65 *
66 * @since 3.7
67 *
68 * @return array Partial schema.
69 *
70 * @phpstan-return array{type: 'array', items: array{type: SchemaType}}
71 */
72 protected function get_data_structure(): array {
73 return array(
74 'type' => 'array',
75 'items' => array(
76 'type' => $this->get_type(),
77 ),
78 );
79 }
80 }
81