Completed
Branch FET/11183/improvements-to-pue-... (232f50)
by
unknown
43:46 queued 26:36
created

BootstrapRequestResponseObjects   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 80
rs 10
wmc 4
lcom 1
cbo 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildRequestResponse() 0 6 1
A shareRequestResponse() 0 7 1
A setupLegacyRequest() 0 15 1
1
<?php
2
3
namespace EventEspresso\core\services\bootstrap;
4
5
use EE_Dependency_Map;
6
use EE_Error;
7
use EE_Request;
8
use EventEspresso\core\services\loaders\LoaderInterface;
9
use EventEspresso\core\services\request\LegacyRequestInterface;
10
use EventEspresso\core\services\request\Request;
11
use EventEspresso\core\services\request\RequestInterface;
12
use EventEspresso\core\services\request\Response;
13
use EventEspresso\core\services\request\ResponseInterface;
14
use InvalidArgumentException;
15
16
defined('EVENT_ESPRESSO_VERSION') || exit;
17
18
19
20
/**
21
 * Class BootstrapRequestResponseObjects
22
 * Sets up the Request and Response objects
23
 * as well as backwards compatibility for the Legacy EE_Request object
24
 *
25
 * @package EventEspresso\core\services\bootstrap
26
 * @author  Brent Christensen
27
 * @since   4.9.53
28
 */
29
class BootstrapRequestResponseObjects
30
{
31
32
    /**
33
     * @type LegacyRequestInterface $legacy_request
34
     */
35
    protected $legacy_request;
36
37
    /**
38
     * @type LoaderInterface $loader
39
     */
40
    protected $loader;
41
42
    /**
43
     * @var RequestInterface $request
44
     */
45
    protected $request;
46
47
    /**
48
     * @var ResponseInterface $response
49
     */
50
    protected $response;
51
52
53
    /**
54
     * BootstrapRequestResponseObjects constructor.
55
     *
56
     * @param LoaderInterface $loader
57
     */
58
    public function __construct(LoaderInterface $loader)
59
    {
60
        $this->loader = $loader;
61
    }
62
63
64
    /**
65
     * @return void
66
     */
67
    public function buildRequestResponse()
68
    {
69
        // load our Request and Response objects
70
        $this->request  = new Request($_GET, $_POST, $_COOKIE, $_SERVER);
71
        $this->response = new Response();
72
    }
73
74
75
    /**
76
     * @return void
77
     * @throws InvalidArgumentException
78
     */
79
    public function shareRequestResponse()
80
    {
81
        $this->loader->share('EventEspresso\core\services\request\Request', $this->request);
82
        $this->loader->share('EventEspresso\core\services\request\Response', $this->response);
83
        EE_Dependency_Map::instance()->setRequest($this->request);
84
        EE_Dependency_Map::instance()->setResponse($this->response);
85
    }
86
87
88
    /**
89
     * @return void
90
     * @throws InvalidArgumentException
91
     * @throws EE_Error
92
     */
93
    public function setupLegacyRequest()
94
    {
95
        espresso_load_required(
96
            'EE_Request',
97
            EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
98
        );
99
        $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER);
0 ignored issues
show
Deprecated Code introduced by
The class EE_Request has been deprecated with message: 4.9.53

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
100
        $this->legacy_request->setRequest($this->request);
101
        $this->legacy_request->admin      = $this->request->isAdmin();
102
        $this->legacy_request->ajax       = $this->request->isAjax();
103
        $this->legacy_request->front_ajax = $this->request->isFrontAjax();
104
        EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request);
105
        $this->loader->share('EE_Request', $this->legacy_request);
106
        $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request);
107
    }
108
}
109
110