Completed
Push — develop ( 9efb3c...1d4e17 )
by David
03:00
created

Wordlift_Property_Service::get_params()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Define the Wordlift_Property_Service abstract class.
5
 *
6
 * @since 3.6.0
7
 */
8
9
/**
10
 * Wordlift_Property_Service provides basic functions and declarations for
11
 * properties that extend WL's schema.
12
 *
13
 * @since 3.6.0
14
 */
15
abstract class Wordlift_Property_Service {
16
17
	// TODO: check that this is relative to the extending class.
18
	protected static $instance;
19
20
	public function __construct() {
21
22
		static::$instance = $this;
23
	}
24
25
	/**
26
	 * Get the field singleton.
27
	 *
28
	 * @since 3.6.0
29
	 * @return \Wordlift_Schema_Url_Property_Service The singleton instance.
30
	 */
31
	public static function get_instance() {
32
33
		return static::$instance;
34
	}
35
36
	/**
37
	 * Get the value for the specified post/entity.
38
	 *
39
	 * @since 3.6.0
40
	 *
41
	 * @param int $post_id The post id.
42
	 *
43
	 * @return mixed
44
	 */
45
	public abstract function get( $post_id );
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
46
47
	/**
48
	 * Sanitize the provided value.
49
	 *
50
	 * @since 3.6.0
51
	 *
52
	 * @param mixed $value The value to sanitize.
53
	 *
54
	 * @return mixed|NULL The sanitized value or NULL avoid saving this value (see {@link WL_Metabox_Field}).
55
	 */
56
	public abstract function sanitize( $value );
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
57
58
	/**
59
	 * The RDF predicate for the property.
60
	 *
61
	 * @since 3.6.0
62
	 * @return string The RDF predicate.
63
	 */
64
	public abstract function get_rdf_predicate();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
65
66
	/**
67
	 * The RDF data type.
68
	 *
69
	 * @since 3.6.0
70
	 * @return string The RDF data type.
71
	 */
72
	public abstract function get_rdf_data_type();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
73
74
	/**
75
	 * The internal data type.
76
	 *
77
	 * @since 3.6.0
78
	 * @return string The internal data type.
79
	 */
80
	public abstract function get_data_type();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
81
82
	/**
83
	 * The cardinality.
84
	 *
85
	 * @since 3.6.0
86
	 * @return mixed The cardinality.
87
	 */
88
	public abstract function get_cardinality();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
89
90
	/**
91
	 * The metabox field class name.
92
	 *
93
	 * @since 3.6.0
94
	 * @return string The metabox field class name.
95
	 */
96
	public abstract function get_metabox_class();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
97
98
	/**
99
	 * The untranslated metabox field label.
100
	 *
101
	 * @since 3.6.0
102
	 * @return string The untranslated metabox field label.
103
	 */
104
	public abstract function get_metabox_label();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
105
106
	/**
107
	 * The definition of the property returned as a compatible array.
108
	 *
109
	 * @deprecated
110
	 * @since 3.6.0
111
	 * @return array An array of property definitions.
112
	 */
113
	public function get_compat_definition() {
114
115
		return array(
116
			'type'        => $this->get_data_type(),
117
			'predicate'   => $this->get_rdf_predicate(),
118
			'export_type' => $this->get_rdf_data_type(),
119
			'constraints' => array(
120
				'cardinality' => $this->get_cardinality()
121
			),
122
			// Use the standard metabox for these URI (the URI metabox creates local entities).
123
			'metabox'     => array(
124
				'class' => $this->get_metabox_class(),
125
				'label' => $this->get_metabox_label()
126
			),
127
			'sanitize'    => array( $this, 'sanitize' )
128
		);
129
	}
130
131
}
132