Completed
Branch FET/rest-relation-endpoints (00c747)
by
unknown
26:56 queued 18:24
created

WordpressHeartbeat   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A resolveRoutes() 0 14 4
1
<?php
2
3
namespace EventEspresso\core\domain\services\admin\ajax;
4
5
use EventEspresso\core\exceptions\InvalidClassException;
6
use EventEspresso\core\services\loaders\LoaderInterface;
7
use EventEspresso\core\services\request\RequestInterface;
8
9
/**
10
 * Class WordpressHeartbeat
11
 * Directs WordPress Heartbeat AJAX requests to the appropriate handler
12
 *
13
 * @package EventEspresso\core\domain\services\admin\ajax
14
 * @author  Brent Christensen
15
 * @since   $VID:$
16
 */
17
class WordpressHeartbeat
18
{
19
20
    /**
21
     * @var LoaderInterface $loader
22
     */
23
    protected $loader;
24
25
    /**
26
     * @var RequestInterface $request
27
     */
28
    protected $request;
29
30
31
    /**
32
     * WordpressHeartbeat constructor.
33
     *
34
     * @param LoaderInterface  $loader
35
     * @param RequestInterface $request
36
     */
37
    public function __construct(
38
        LoaderInterface $loader,
39
        RequestInterface $request
40
    ) {
41
        $this->loader = $loader;
42
        $this->request = $request;
43
        do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this);
44
        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes'));
45
    }
46
47
48
    /**
49
     * @since $VID:$
50
     * @throws InvalidClassException
51
     */
52
    public function resolveRoutes()
53
    {
54
        $screenID = $this->request->getRequestParam('screen_id');
55
        $heartbeat_data = $this->request->getRequestParam('data', []);
56
        if ($screenID === 'espresso_events') {
57
            $this->loader->getShared(
58
                'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat'
59
            );
60
        } elseif ($screenID === 'front' && ! empty($heartbeat_data['espresso_thank_you_page'])) {
61
            $this->loader->getShared(
62
                'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor'
63
            );
64
        }
65
    }
66
}
67