1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Entity context base class. |
5
|
|
|
* |
6
|
|
|
* @package wordpoints-hooks-api |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Bootstrap for representing an entity context. |
12
|
|
|
* |
13
|
|
|
* The entity API makes it possible to encapsulate different sorts of things (like |
14
|
|
|
* posts and users) so that their data can be accessed through a common set of |
15
|
|
|
* interfaces. Each entity has an ID—a single piece of data (like an integer or |
16
|
|
|
* string) that can be used to identify that entity. The ID is unique to that entity, |
17
|
|
|
* but it is not *globally unique*. That is, it is unique to that entity only within |
18
|
|
|
* a particular scope or "context". For example, on multisite a post's ID is unique |
19
|
|
|
* only in the context of the site on which that post was published. That same ID |
20
|
|
|
* would refer to a different post on each other site on the network. The job of the |
21
|
|
|
* context API is to encapsulate the different sorts of contexts in which entities |
22
|
|
|
* can exist. This allows us to, for example, create globally unique IDs (GUIDs) for |
23
|
|
|
* entities, so that they can be identified specifically even outside of their usual |
24
|
|
|
* context. |
25
|
|
|
* |
26
|
|
|
* @since 1.0.0 |
27
|
|
|
*/ |
28
|
|
|
abstract class WordPoints_Entity_Context { |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The slug of this context. |
32
|
|
|
* |
33
|
|
|
* @since 1.0.0 |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $slug; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The slug of the parent of this context, if this is a sub-context. |
41
|
|
|
* |
42
|
|
|
* @since 1.0.0 |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $parent_slug; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @since 1.0.0 |
50
|
|
|
* |
51
|
|
|
* @param string $slug The slug of this context. |
52
|
|
|
*/ |
53
|
|
|
public function __construct( $slug ) { |
54
|
|
|
$this->slug = $slug; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the slug of this context. |
59
|
|
|
* |
60
|
|
|
* @since 1.0.0 |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function get_slug() { |
65
|
|
|
return $this->slug; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the slug of the parent of this context, if it is a sub-context. |
70
|
|
|
* |
71
|
|
|
* Most contexts are really children of other contexts. For example, the 'site' |
72
|
|
|
* context is a child of the 'network' context, since sites can only exist within |
73
|
|
|
* a network. |
74
|
|
|
* |
75
|
|
|
* @since 1.0.0 |
76
|
|
|
* |
77
|
|
|
* @return string|null The slug of the parent context, or null if none. |
78
|
|
|
*/ |
79
|
|
|
public function get_parent_slug() { |
80
|
|
|
return $this->parent_slug; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the current ID of this context. |
85
|
|
|
* |
86
|
|
|
* @since 1.0.0 |
87
|
|
|
* |
88
|
|
|
* @return int|string|false The ID or slug of the context, or false if not |
89
|
|
|
* currently in this context. |
90
|
|
|
*/ |
91
|
|
|
abstract public function get_current_id(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// EOF |
95
|
|
|
|