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() { |
||
186 | |||
187 | /** |
||
188 | * run the plugin, independent of activation methods. |
||
189 | * |
||
190 | */ |
||
191 | public function run() { |
||
212 | |||
213 | /** |
||
214 | * Load immediately required things |
||
215 | * |
||
216 | * @param object $wpdb |
||
217 | * @param string $version |
||
218 | * @param string $slug |
||
219 | * @param string $option_prefix |
||
220 | * |
||
221 | */ |
||
222 | private function load( $wpdb, $version, $slug, $option_prefix ) { |
||
225 | |||
226 | /** |
||
227 | * Get queue instance. |
||
228 | * |
||
229 | * @param object $wpdb |
||
230 | * @param string $version |
||
231 | * @param string $slug |
||
232 | * @param string $option_prefix |
||
233 | * @param array $schedulable_classes |
||
234 | * @return Object_Sync_Sf_Queue |
||
235 | */ |
||
236 | private function queue( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ) { |
||
241 | |||
242 | /** |
||
243 | * Log events |
||
244 | * |
||
245 | * @param object $wpdb |
||
246 | * @param string $version |
||
247 | * @param string $slug |
||
248 | * @param string $option_prefix |
||
249 | * |
||
250 | * @return object |
||
251 | * Instance of Object_Sync_Sf_Logging |
||
252 | */ |
||
253 | private function logging( $wpdb, $version, $slug, $option_prefix ) { |
||
258 | |||
259 | /** |
||
260 | * Map the Salesforce and WordPress objects and fields to each other |
||
261 | * |
||
262 | * @param object $wpdb |
||
263 | * @param string $version |
||
264 | * @param string $slug |
||
265 | * @param string $option_prefix |
||
266 | * @param object $logging |
||
267 | * |
||
268 | * @return object |
||
269 | * Instance of Object_Sync_Sf_Mapping |
||
270 | */ |
||
271 | private function mappings( $wpdb, $version, $slug, $option_prefix, $logging ) { |
||
276 | |||
277 | /** |
||
278 | * Private helper to load methods for manipulating core WordPress data across the plugin |
||
279 | * |
||
280 | * @param object $wpdb |
||
281 | * @param string $version |
||
282 | * @param string $slug |
||
283 | * @param string $option_prefix |
||
284 | * @param object $mappings |
||
285 | * @param object $logging |
||
286 | * |
||
287 | * @return object |
||
288 | * Instance of Object_Sync_Sf_WordPress |
||
289 | */ |
||
290 | private function wordpress( $wpdb, $version, $slug, $option_prefix, $mappings, $logging ) { |
||
295 | |||
296 | /** |
||
297 | * Public helper to load the Salesforce API and see if it is authenticated. |
||
298 | * This is public so other plugins can access the same SF API instance |
||
299 | * |
||
300 | * @return array |
||
301 | * Whether Salesforce is authenticated (boolean) |
||
302 | * The sfapi object if it is authenticated (empty, otherwise) |
||
303 | */ |
||
304 | public function salesforce_get_api() { |
||
332 | |||
333 | /** |
||
334 | * What to do upon activation of the plugin |
||
335 | * |
||
336 | * @param object $wpdb |
||
337 | * @param string $version |
||
338 | * @param string $slug |
||
339 | * @param string $option_prefix |
||
340 | * @param array $schedulable_classes |
||
341 | * @param object $queue |
||
342 | * |
||
343 | * @return object |
||
344 | * Instance of Object_Sync_Sf_Activate |
||
345 | */ |
||
346 | private function activate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) { |
||
351 | |||
352 | /** |
||
353 | * What to do upon deactivation of the plugin |
||
354 | * |
||
355 | * @param object $wpdb |
||
356 | * @param string $version |
||
357 | * @param string $slug |
||
358 | * @param string $option_prefix |
||
359 | * @param array $schedulable_classes |
||
360 | * @param object $queue |
||
361 | * |
||
362 | * @return object |
||
363 | * Instance of Object_Sync_Sf_Deactivate |
||
364 | */ |
||
365 | private function deactivate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) { |
||
369 | |||
370 | |||
371 | /** |
||
372 | * Methods to push data from WordPress to Salesforce |
||
373 | * |
||
374 | * @param object $wpdb |
||
375 | * @param string $version |
||
376 | * @param array $login_credentials |
||
377 | * @param string $slug |
||
378 | * @param string $object_prefix |
||
379 | * @param object $wordpress |
||
380 | * @param object $salesforce |
||
381 | * @param object $mappings |
||
382 | * @param object $logging |
||
383 | * @param array $schedulable_classes |
||
384 | * |
||
385 | * @return object |
||
386 | * Instance of Object_Sync_Sf_Salesforce_Push |
||
387 | */ |
||
388 | private function push( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
||
393 | |||
394 | /** |
||
395 | * Methods to pull data from Salesforce to WordPress |
||
396 | * |
||
397 | * @param object $wpdb |
||
398 | * @param string $version |
||
399 | * @param array $login_credentials |
||
400 | * @param string $slug |
||
401 | * @param string $option_prefix |
||
402 | * @param object $wordpress |
||
403 | * @param object $salesforce |
||
404 | * @param object $mappings |
||
405 | * @param object $logging |
||
406 | * @param array $schedulable_classes |
||
407 | * @return object |
||
408 | * Instance of Object_Sync_Sf_Salesforce_Pull |
||
409 | */ |
||
410 | private function pull( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
||
415 | |||
416 | /** |
||
417 | * Load the rest class. |
||
418 | * This handles REST API methods |
||
419 | * |
||
420 | * @param object $wpdb |
||
421 | * @param string $version |
||
422 | * @param array $login_credentials |
||
423 | * @param string $slug |
||
424 | * @param string $option_prefix |
||
425 | * @param object $wordpress |
||
426 | * @param object $salesforce |
||
427 | * @param object $mappings |
||
428 | * @param object $push |
||
429 | * @param object $pull |
||
430 | * @param object $logging |
||
431 | * @param array $schedulable_classes |
||
432 | * @param object $queue |
||
433 | * @return object $admin |
||
434 | * Instance of Object_Sync_Sf_Rest |
||
435 | * |
||
436 | */ |
||
437 | private function rest( $wpdb, $version, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull ) { |
||
442 | |||
443 | /** |
||
444 | * Load the admin class. |
||
445 | * This also creates admin menu, unless the plugin that calls this library has indicated that it has its own menu |
||
446 | * |
||
447 | * @param object $wpdb |
||
448 | * @param string $version |
||
449 | * @param array $login_credentials |
||
450 | * @param string $slug |
||
451 | * @param string $option_prefix |
||
452 | * @param object $wordpress |
||
453 | * @param object $salesforce |
||
454 | * @param object $mappings |
||
455 | * @param object $push |
||
456 | * @param object $pull |
||
457 | * @param object $logging |
||
458 | * @param array $schedulable_classes |
||
459 | * @param object $queue |
||
460 | * @return object $admin |
||
461 | * Instance of Object_Sync_Sf_Admin |
||
462 | * |
||
463 | */ |
||
464 | private function load_admin( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) { |
||
473 | |||
474 | /** |
||
475 | * Display a Settings link on the main Plugins page |
||
476 | * |
||
477 | * @param array $links |
||
478 | * @param string $file |
||
479 | * @return array $links |
||
480 | * These are the links that go with this plugin's entry |
||
481 | */ |
||
482 | public function plugin_action_links( $links, $file ) { |
||
490 | |||
491 | |||
492 | /** |
||
493 | * Admin styles. Load the CSS and JavaScript for the plugin's settings |
||
494 | * |
||
495 | * @return void |
||
496 | */ |
||
497 | public function admin_scripts_and_styles() { |
||
526 | |||
527 | /** |
||
528 | * Load textdomain |
||
529 | * |
||
530 | * @return void |
||
531 | */ |
||
532 | public function textdomain() { |
||
535 | |||
536 | /** |
||
537 | * Get the pre-login Salesforce credentials. |
||
538 | * These depend on the plugin's settings or constants defined in wp-config.php. |
||
539 | * |
||
540 | * @return array $login_credentials |
||
541 | * Includes all settings necessary to log into the Salesforce API. |
||
542 | * Replaces settings options with wp-config.php values if they exist. |
||
543 | */ |
||
544 | private function get_login_credentials() { |
||
567 | |||
568 | } // end class |
||
569 | |||
572 |
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.