Completed
Branch FET/remove-bot-trap-timestamp (248d53)
by
unknown
61:37 queued 52:14
created

EventEditorHeartbeat::heartbeatResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\services\admin\ajax;
4
5
use EE_Environment_Config;
6
use EventEspresso\core\domain\Domain;
7
8
/**
9
 * Class EventEditorHeartbeat
10
 * Handles WordPress Heartbeat AJAX requests for the Espresso Event Editor
11
 *
12
 * @package EventEspresso\core\domain\services\admin\ajax
13
 * @author  Brent Christensen
14
 * @since   $VID:$
15
 */
16
class EventEditorHeartbeat
17
{
18
19
    /**
20
     * @var Domain $domain
21
     */
22
    protected $domain;
23
24
    /**
25
     * @var EE_Environment_Config $environment
26
     */
27
    protected $environment;
28
29
30
    /**
31
     * EventEditorHeartbeat constructor.
32
     *
33
     * @param Domain                $domain
34
     * @param EE_Environment_Config $environment
35
     */
36
    public function __construct(Domain $domain, EE_Environment_Config $environment)
37
    {
38
        $this->domain = $domain;
39
        $this->environment = $environment;
40
        if ($this->domain->isCaffeinated()) {
41
            add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2);
42
        }
43
    }
44
45
46
    /**
47
     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
48
     * accordingly.
49
     *
50
     * @param array $response The existing heartbeat response array.
51
     * @param array $data     The incoming data package.
52
     * @return array  possibly appended response.
53
     */
54
    public function heartbeatResponse($response, $data)
55
    {
56
        /**
57
         * check whether count of tickets is approaching the potential
58
         * limits for the server.
59
         */
60
        if (! empty($data['input_count'])) {
61
            $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62
                $data['input_count']
63
            );
64
        }
65
        return $response;
66
    }
67
}
68