Completed
Push — master ( 6730cd...13507f )
by J.D.
03:41
created

WordPoints_Entity_Context::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
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
	 * @since 1.0.0
41
	 *
42
	 * @param string $slug The slug of this context.
43
	 */
44
	public function __construct( $slug ) {
45
		$this->slug = $slug;
46
	}
47
48
	/**
49
	 * Get the slug of this context.
50
	 *
51
	 * @since 1.0.0
52
	 *
53
	 * @return string
54
	 */
55
	public function get_slug() {
56
		return $this->slug;
57
	}
58
59
	/**
60
	 * Get the current ID of this context.
61
	 *
62
	 * @since 1.0.0
63
	 *
64
	 * @return int|string|false The ID or slug of the context, or false if not
65
	 *                          currently in this context.
66
	 */
67
	abstract public function get_current_id();
68
}
69
70
// EOF
71