1 | <?php |
||
5 | class Manager |
||
6 | { |
||
7 | /** |
||
8 | * @var Singleton The reference to *Singleton* instance of this class |
||
9 | */ |
||
10 | private static $instance; |
||
11 | |||
12 | private $pages = array(); |
||
13 | |||
14 | private $child_pages = array(); |
||
15 | |||
16 | /** |
||
17 | * Returns the *Singleton* instance of this class. |
||
18 | * |
||
19 | * @return Singleton The *Singleton* instance. |
||
20 | */ |
||
21 | public static function get_instance() |
||
29 | |||
30 | /** |
||
31 | * Add a page to the admin menu. |
||
32 | * |
||
33 | * @param array $args |
||
34 | * @throws \RuntimeException |
||
35 | */ |
||
36 | public function add_page($args) |
||
45 | |||
46 | /** |
||
47 | * Get a page from the set of registered pages. |
||
48 | * |
||
49 | * @param string $slug |
||
50 | * @return Page |
||
51 | * @throws \RuntimeException If no page was found for the given slug |
||
52 | */ |
||
53 | public function get_page($slug) |
||
61 | |||
62 | /** |
||
63 | * Add a child setting page. |
||
64 | * |
||
65 | * @param array $args |
||
66 | */ |
||
67 | public function add_child_page($args) |
||
76 | |||
77 | /** |
||
78 | * Get a child page from the set of registered child pages. |
||
79 | * |
||
80 | * @param string $slug |
||
81 | * @param string $parent_slug |
||
82 | * @return ChildPage |
||
83 | * @throws \RuntimeException If no child page was found for the given slug/parent_slug |
||
84 | */ |
||
85 | public function get_child_page($slug, $parent_slug) |
||
94 | |||
95 | /** |
||
96 | * Get the value of the given field. |
||
97 | * |
||
98 | * @param [string] $field_name |
||
99 | * @return mixed |
||
100 | */ |
||
101 | public function get_field_value($field_name) |
||
117 | |||
118 | /** |
||
119 | * Get the value of a field within a parent page. |
||
120 | * |
||
121 | * @param [string] $parent_slug |
||
122 | * @param [string] $field_name |
||
123 | * @throws RuntimeException if no field was found with the given name |
||
124 | * @return mixed |
||
125 | */ |
||
126 | public function get_field_value_for_parent($parent_slug, $field_name) |
||
143 | |||
144 | /** |
||
145 | * Register styles & scripts to be enqueued by settings child pages |
||
146 | */ |
||
147 | public function register_scripts() |
||
152 | |||
153 | /** |
||
154 | * Private constructor to prevent instantiation |
||
155 | */ |
||
156 | private function __construct() |
||
160 | |||
161 | /** |
||
162 | * Register scripts and initiate the request handler. |
||
163 | */ |
||
164 | private function init() |
||
171 | } |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: