1 | <?php |
||
13 | abstract class WP_Async_Request { |
||
14 | |||
15 | /** |
||
16 | * Prefix |
||
17 | * |
||
18 | * (default value: 'wp') |
||
19 | * |
||
20 | * @var string |
||
21 | * @access protected |
||
22 | */ |
||
23 | protected $prefix = 'wp'; |
||
24 | |||
25 | /** |
||
26 | * Action |
||
27 | * |
||
28 | * (default value: 'async_request') |
||
29 | * |
||
30 | * @var string |
||
31 | * @access protected |
||
32 | */ |
||
33 | protected $action = 'async_request'; |
||
34 | |||
35 | /** |
||
36 | * Identifier |
||
37 | * |
||
38 | * @var mixed |
||
39 | * @access protected |
||
40 | */ |
||
41 | protected $identifier; |
||
42 | |||
43 | /** |
||
44 | * Data |
||
45 | * |
||
46 | * (default value: array()) |
||
47 | * |
||
48 | * @var array |
||
49 | * @access protected |
||
50 | */ |
||
51 | protected $data = array(); |
||
52 | |||
53 | /** |
||
54 | * Initiate new async request |
||
55 | */ |
||
56 | public function __construct() { |
||
62 | |||
63 | /** |
||
64 | * Set data used during the request |
||
65 | * |
||
66 | * @param array $data Data. |
||
67 | * |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function data( $data ) { |
||
75 | |||
76 | /** |
||
77 | * Dispatch the async request |
||
78 | * |
||
79 | * @return array|WP_Error |
||
80 | */ |
||
81 | public function dispatch() { |
||
87 | |||
88 | /** |
||
89 | * Get query args |
||
90 | * |
||
91 | * @return array |
||
92 | */ |
||
93 | protected function get_query_args() { |
||
103 | |||
104 | /** |
||
105 | * Get query URL |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | protected function get_query_url() { |
||
116 | |||
117 | /** |
||
118 | * Get post args |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | protected function get_post_args() { |
||
135 | |||
136 | /** |
||
137 | * Maybe handle |
||
138 | * |
||
139 | * Check for correct nonce and pass to handler. |
||
140 | */ |
||
141 | public function maybe_handle() { |
||
151 | |||
152 | /** |
||
153 | * Handle |
||
154 | * |
||
155 | * Override this method to perform any actions required |
||
156 | * during the async request. |
||
157 | */ |
||
158 | abstract protected function handle(); |
||
159 | |||
160 | } |
||
161 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: