1 | <?php |
||
16 | class Object_Sync_Salesforce { |
||
17 | |||
18 | /** |
||
19 | * @var object |
||
20 | * Global object of `$wpdb`, the WordPress database |
||
21 | */ |
||
22 | private $wpdb; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | * The plugin's slug so we can include it when necessary |
||
27 | */ |
||
28 | private $slug; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | * The plugin's option prefix |
||
33 | */ |
||
34 | private $option_prefix; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | * Login credentials for the Salesforce API; comes from wp-config or from the plugin settings |
||
39 | */ |
||
40 | private $login_credentials; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | * Array of what classes in the plugin can be scheduled to occur with `wp_cron` events |
||
45 | */ |
||
46 | public $schedulable_classes; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | * Current version of the plugin |
||
51 | */ |
||
52 | private $version; |
||
53 | |||
54 | /** |
||
55 | * @var object |
||
56 | */ |
||
57 | private $queue; |
||
58 | |||
59 | /** |
||
60 | * @var object |
||
61 | */ |
||
62 | private $activated; |
||
63 | |||
64 | /** |
||
65 | * @var object |
||
66 | * Load and initialize the Object_Sync_Sf_Logging class |
||
67 | */ |
||
68 | private $logging; |
||
69 | |||
70 | /** |
||
71 | * @var object |
||
72 | * Load and initialize the Object_Sync_Sf_Mapping class |
||
73 | */ |
||
74 | public $mappings; |
||
75 | |||
76 | /** |
||
77 | * @var object |
||
78 | * Load and initialize the Object_Sync_Sf_WordPress class |
||
79 | */ |
||
80 | private $wordpress; |
||
81 | |||
82 | /** |
||
83 | * @var object |
||
84 | * Load and initialize the Object_Sync_Sf_Salesforce class. |
||
85 | * This contains the Salesforce API methods |
||
86 | */ |
||
87 | public $salesforce; |
||
88 | |||
89 | /** |
||
90 | * @var object |
||
91 | * Load and initialize the Object_Sync_Sf_Salesforce_Push class |
||
92 | */ |
||
93 | private $push; |
||
94 | |||
95 | /** |
||
96 | * @var object |
||
97 | * Load and initialize the Object_Sync_Sf_Salesforce_Pull class |
||
98 | */ |
||
99 | private $pull; |
||
100 | |||
101 | /** |
||
102 | * @var object |
||
103 | * Static property to hold an instance of the class; this seems to make it reusable |
||
104 | * |
||
105 | */ |
||
106 | static $instance = null; |
||
107 | |||
108 | /** |
||
109 | * Load the static $instance property that holds the instance of the class. |
||
110 | * This instance makes the class reusable by other plugins |
||
111 | * |
||
112 | * @return object |
||
113 | * The sfapi object if it is authenticated (empty, otherwise) |
||
114 | * |
||
115 | */ |
||
116 | static public function get_instance() { |
||
122 | |||
123 | /** |
||
124 | * Constructor that sets up the parameters to pass to all the other classes, and the methods that call the other classes |
||
125 | * |
||
126 | * @return void |
||
|
|||
127 | */ |
||
128 | protected function __construct() { |
||
201 | |||
202 | /** |
||
203 | * Load immediately required things |
||
204 | * |
||
205 | * @param object $wpdb |
||
206 | * @param string $version |
||
207 | * @param string $slug |
||
208 | * @param string $option_prefix |
||
209 | * |
||
210 | */ |
||
211 | private function load( $wpdb, $version, $slug, $option_prefix ) { |
||
214 | |||
215 | /** |
||
216 | * Get queue instance. |
||
217 | * |
||
218 | * @param object $wpdb |
||
219 | * @param string $version |
||
220 | * @param string $slug |
||
221 | * @param string $option_prefix |
||
222 | * @param array $schedulable_classes |
||
223 | * @return Object_Sync_Sf_Queue |
||
224 | */ |
||
225 | private function queue( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ) { |
||
230 | |||
231 | /** |
||
232 | * Log events |
||
233 | * |
||
234 | * @param object $wpdb |
||
235 | * @param string $version |
||
236 | * @param string $slug |
||
237 | * @param string $option_prefix |
||
238 | * |
||
239 | * @return object |
||
240 | * Instance of Object_Sync_Sf_Logging |
||
241 | */ |
||
242 | private function logging( $wpdb, $version, $slug, $option_prefix ) { |
||
247 | |||
248 | /** |
||
249 | * Map the Salesforce and WordPress objects and fields to each other |
||
250 | * |
||
251 | * @param object $wpdb |
||
252 | * @param string $version |
||
253 | * @param string $slug |
||
254 | * @param string $option_prefix |
||
255 | * @param object $logging |
||
256 | * |
||
257 | * @return object |
||
258 | * Instance of Object_Sync_Sf_Mapping |
||
259 | */ |
||
260 | private function mappings( $wpdb, $version, $slug, $option_prefix, $logging ) { |
||
265 | |||
266 | /** |
||
267 | * Private helper to load methods for manipulating core WordPress data across the plugin |
||
268 | * |
||
269 | * @param object $wpdb |
||
270 | * @param string $version |
||
271 | * @param string $slug |
||
272 | * @param string $option_prefix |
||
273 | * @param object $mappings |
||
274 | * @param object $logging |
||
275 | * |
||
276 | * @return object |
||
277 | * Instance of Object_Sync_Sf_WordPress |
||
278 | */ |
||
279 | private function wordpress( $wpdb, $version, $slug, $option_prefix, $mappings, $logging ) { |
||
284 | |||
285 | /** |
||
286 | * Public helper to load the Salesforce API and see if it is authenticated. |
||
287 | * This is public so other plugins can access the same SF API instance |
||
288 | * |
||
289 | * @return array |
||
290 | * Whether Salesforce is authenticated (boolean) |
||
291 | * The sfapi object if it is authenticated (empty, otherwise) |
||
292 | */ |
||
293 | public function salesforce_get_api() { |
||
321 | |||
322 | /** |
||
323 | * What to do upon activation of the plugin |
||
324 | * |
||
325 | * @param object $wpdb |
||
326 | * @param string $version |
||
327 | * @param string $slug |
||
328 | * @param string $option_prefix |
||
329 | * @param array $schedulable_classes |
||
330 | * @param object $queue |
||
331 | * |
||
332 | * @return object |
||
333 | * Instance of Object_Sync_Sf_Activate |
||
334 | */ |
||
335 | private function activate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) { |
||
340 | |||
341 | /** |
||
342 | * What to do upon deactivation of the plugin |
||
343 | * |
||
344 | * @param object $wpdb |
||
345 | * @param string $version |
||
346 | * @param string $slug |
||
347 | * @param string $option_prefix |
||
348 | * @param array $schedulable_classes |
||
349 | * @param object $queue |
||
350 | * |
||
351 | * @return object |
||
352 | * Instance of Object_Sync_Sf_Deactivate |
||
353 | */ |
||
354 | private function deactivate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) { |
||
358 | |||
359 | |||
360 | /** |
||
361 | * Methods to push data from WordPress to Salesforce |
||
362 | * |
||
363 | * @param object $wpdb |
||
364 | * @param string $version |
||
365 | * @param array $login_credentials |
||
366 | * @param string $slug |
||
367 | * @param string $object_prefix |
||
368 | * @param object $wordpress |
||
369 | * @param object $salesforce |
||
370 | * @param object $mappings |
||
371 | * @param object $logging |
||
372 | * @param array $schedulable_classes |
||
373 | * |
||
374 | * @return object |
||
375 | * Instance of Object_Sync_Sf_Salesforce_Push |
||
376 | */ |
||
377 | private function push( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
||
382 | |||
383 | /** |
||
384 | * Methods to pull data from Salesforce to WordPress |
||
385 | * |
||
386 | * @param object $wpdb |
||
387 | * @param string $version |
||
388 | * @param array $login_credentials |
||
389 | * @param string $slug |
||
390 | * @param string $option_prefix |
||
391 | * @param object $wordpress |
||
392 | * @param object $salesforce |
||
393 | * @param object $mappings |
||
394 | * @param object $logging |
||
395 | * @param array $schedulable_classes |
||
396 | * @return object |
||
397 | * Instance of Object_Sync_Sf_Salesforce_Pull |
||
398 | */ |
||
399 | private function pull( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
||
404 | |||
405 | /** |
||
406 | * Load the rest class. |
||
407 | * This handles REST API methods |
||
408 | * |
||
409 | * @param object $wpdb |
||
410 | * @param string $version |
||
411 | * @param array $login_credentials |
||
412 | * @param string $slug |
||
413 | * @param string $option_prefix |
||
414 | * @param object $wordpress |
||
415 | * @param object $salesforce |
||
416 | * @param object $mappings |
||
417 | * @param object $push |
||
418 | * @param object $pull |
||
419 | * @param object $logging |
||
420 | * @param array $schedulable_classes |
||
421 | * @param object $queue |
||
422 | * @return object $admin |
||
423 | * Instance of Object_Sync_Sf_Rest |
||
424 | * |
||
425 | */ |
||
426 | private function rest( $wpdb, $version, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull ) { |
||
431 | |||
432 | /** |
||
433 | * Load the admin class. |
||
434 | * This also creates admin menu, unless the plugin that calls this library has indicated that it has its own menu |
||
435 | * |
||
436 | * @param object $wpdb |
||
437 | * @param string $version |
||
438 | * @param array $login_credentials |
||
439 | * @param string $slug |
||
440 | * @param string $option_prefix |
||
441 | * @param object $wordpress |
||
442 | * @param object $salesforce |
||
443 | * @param object $mappings |
||
444 | * @param object $push |
||
445 | * @param object $pull |
||
446 | * @param object $logging |
||
447 | * @param array $schedulable_classes |
||
448 | * @param object $queue |
||
449 | * @return object $admin |
||
450 | * Instance of Object_Sync_Sf_Admin |
||
451 | * |
||
452 | */ |
||
453 | private function load_admin( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) { |
||
462 | |||
463 | /** |
||
464 | * Display a Settings link on the main Plugins page |
||
465 | * |
||
466 | * @param array $links |
||
467 | * @param string $file |
||
468 | * @return array $links |
||
469 | * These are the links that go with this plugin's entry |
||
470 | */ |
||
471 | public function plugin_action_links( $links, $file ) { |
||
479 | |||
480 | |||
481 | /** |
||
482 | * Admin styles. Load the CSS and JavaScript for the plugin's settings |
||
483 | * |
||
484 | * @return void |
||
485 | */ |
||
486 | public function admin_scripts_and_styles() { |
||
515 | |||
516 | /** |
||
517 | * Load textdomain |
||
518 | * |
||
519 | * @return void |
||
520 | */ |
||
521 | public function textdomain() { |
||
524 | |||
525 | /** |
||
526 | * Get the pre-login Salesforce credentials. |
||
527 | * These depend on the plugin's settings or constants defined in wp-config.php. |
||
528 | * |
||
529 | * @return array $login_credentials |
||
530 | * Includes all settings necessary to log into the Salesforce API. |
||
531 | * Replaces settings options with wp-config.php values if they exist. |
||
532 | */ |
||
533 | private function get_login_credentials() { |
||
556 | |||
557 | } // end class |
||
558 | |||
561 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.