1 | <?php |
||
11 | class Stencil_Handler_Factory implements Stencil_Handler_Factory_Interface { |
||
12 | |||
13 | /** |
||
14 | * Format the class name: |
||
15 | */ |
||
16 | const CLASS_FORMAT = 'Stencil_%s'; |
||
17 | |||
18 | /** |
||
19 | * List of registered Handlers |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private static $handlers = array(); |
||
24 | |||
25 | /** |
||
26 | * Set a hierarchy handler for a page |
||
27 | * |
||
28 | * @param string $page Page to set. |
||
29 | * @param array|Traversable|null $handler Optional. Handler to use. |
||
30 | */ |
||
31 | public static function set_hierarchy_handler( $page, $handler = null ) { |
||
34 | |||
35 | /** |
||
36 | * Set a page type handler |
||
37 | * |
||
38 | * @param string $page Page to set. |
||
39 | * @param callable $handler Handler to use. |
||
40 | */ |
||
41 | public static function set_page_type_handler( $page, $handler ) { |
||
44 | |||
45 | /** |
||
46 | * Remove handler for a page. |
||
47 | * |
||
48 | * @param string $page Page to remove from. |
||
49 | */ |
||
50 | public static function remove_page_type_handler( $page ) { |
||
53 | |||
54 | /** |
||
55 | * Set page type hooking function |
||
56 | * |
||
57 | * @param string $page Page to set to. |
||
58 | * @param callable $handler Handler to use. |
||
59 | */ |
||
60 | public static function set_page_type_hooker( $page, $handler ) { |
||
63 | |||
64 | /** |
||
65 | * Remove page hooker from page |
||
66 | * |
||
67 | * @param string $page Page to remove from. |
||
68 | */ |
||
69 | public static function remove_page_type_hooker( $page ) { |
||
72 | |||
73 | /** |
||
74 | * Get current hierarchy handler for page |
||
75 | * |
||
76 | * @param string $page Page to get from. |
||
77 | * |
||
78 | * @return array|Traversable |
||
79 | */ |
||
80 | public static function get_hierarchy_handler( $page ) { |
||
83 | |||
84 | /** |
||
85 | * Get the current page type handler |
||
86 | * |
||
87 | * @param string $page Page to get from. |
||
88 | * |
||
89 | * @return callable |
||
90 | */ |
||
91 | public static function get_page_type_handler( $page ) { |
||
94 | |||
95 | /** |
||
96 | * Get the current page type hooker |
||
97 | * |
||
98 | * @param string $page Page to get from. |
||
99 | * |
||
100 | * @return callable |
||
101 | */ |
||
102 | public static function get_page_type_hooker( $page ) { |
||
105 | |||
106 | /** |
||
107 | * Run the handler for the specified page |
||
108 | * |
||
109 | * @param string $page Page to call handler for |
||
110 | * @param Stencil_Handler_Interface $controller Controller that initiated the call |
||
111 | */ |
||
112 | public static function run_page_type_handler( $page, Stencil_Handler_Interface $controller ) { |
||
115 | |||
116 | /** |
||
117 | * Run the hooker for the specified page |
||
118 | * |
||
119 | * @param string $page Page to call handler for |
||
120 | * @param Stencil_Handler_Interface $controller Controller that initiated the call |
||
121 | */ |
||
122 | public static function run_page_type_hook( $page, Stencil_Handler_Interface $controller ) { |
||
125 | |||
126 | /** |
||
127 | * Execute a handler if it is callable |
||
128 | * |
||
129 | * @param callable|array $handler The handler for the page requested |
||
130 | * @param Stencil_Handler_Interface $controller Controller that initiated the call |
||
131 | */ |
||
132 | private static function execute_handler( $handler, Stencil_Handler_Interface $controller ) { |
||
137 | |||
138 | /** |
||
139 | * Unified setter function |
||
140 | * |
||
141 | * @param string $type Type of object. |
||
142 | * @param string $page Page name. |
||
143 | * @param mixed|null $handler Handler to apply. |
||
144 | * |
||
145 | * @throws InvalidArgumentException For invalid argument types. |
||
146 | */ |
||
147 | private static function set_settable_handler( $type, $page, $handler = null ) { |
||
169 | |||
170 | /** |
||
171 | * Unified getter function |
||
172 | * |
||
173 | * @param string $page Page to get from. |
||
174 | * @param string $type Type to get. |
||
175 | * |
||
176 | * @return array Callable function |
||
177 | */ |
||
178 | private static function get_settable_handler( $page, $type ) { |
||
195 | } |
||
196 |