Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
11 / 11
CRAP
100.00% covered (success)
100.00%
1 / 1
HttpTrait
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
11 / 11
11
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 application
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 request
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 response
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getApplication
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setApplication
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setRequest
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setResponse
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 hasApplication
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasRequest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Dispatch;
16
17use Pop\Application;
18use Pop\Http\Server\Request;
19use Pop\Http\Server\Response;
20use Pop\Http\Uri;
21
22/**
23 * Pop HTTP trait
24 *
25 * @category   Pop
26 * @package    Pop\Dispatch
27 * @author     Nick Sagona, III <nick@popphp.org>
28 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
29 * @license    https://www.popphp.org/license     New BSD License
30 * @version    5.0.0
31 */
32trait HttpTrait
33{
34
35    /**
36     * Application object
37     * @var ?Application
38     */
39    protected ?Application $application = null;
40
41    /**
42     * Request object
43     * @var ?Request
44     */
45    protected ?Request $request = null;
46
47    /**
48     * Response object
49     * @var ?Response
50     */
51    protected ?Response $response = null;
52
53    /**
54     * Constructor for the controller
55     *
56     * @param  ?Application $application
57     * @param  Request     $request
58     * @param  Response    $response
59     */
60    public function __construct(
61        ?Application $application = null, Request $request = new Request(new Uri()), Response $response = new Response()
62    )
63    {
64        $this->application = $application;
65        $this->request     = $request;
66        $this->response    = $response;
67    }
68
69    /**
70     * Get application object (alias)
71     *
72     * @return ?Application
73     */
74    public function application(): ?Application
75    {
76        return $this->application;
77    }
78
79    /**
80     * Get request object(alias)
81     *
82     * @return ?Request
83     */
84    public function request(): ?Request
85    {
86        return $this->request;
87    }
88
89    /**
90     * Get response object(alias)
91     *
92     * @return ?Response
93     */
94    public function response(): ?Response
95    {
96        return $this->response;
97    }
98
99    /**
100     * Get application object
101     *
102     * @return ?Application
103     */
104    public function getApplication(): ?Application
105    {
106        return $this->application;
107    }
108
109    /**
110     * Set application object
111     *
112     * @param  Application $application
113     * @return static
114     */
115    public function setApplication(Application $application): static
116    {
117        $this->application = $application;
118        return $this;
119    }
120
121    /**
122     * Set request object
123     *
124     * @param  Request $request
125     * @return static
126     */
127    public function setRequest(Request $request = new Request(new Uri())): static
128    {
129        $this->request = $request;
130        return $this;
131    }
132
133    /**
134     * Set response object
135     *
136     * @param  Response $response
137     * @return static
138     */
139    public function setResponse(Response $response = new Response()): static
140    {
141        $this->response = $response;
142        return $this;
143    }
144
145    /**
146     * Has application object
147     *
148     * @return bool
149     */
150    public function hasApplication(): bool
151    {
152        return !empty($this->application);
153    }
154
155    /**
156     * Has request object
157     *
158     * @return bool
159     */
160    public function hasRequest(): bool
161    {
162        return !empty($this->request);
163    }
164
165    /**
166     * Has response object
167     *
168     * @return bool
169     */
170    public function hasResponse(): bool
171    {
172        return !empty($this->response);
173    }
174
175}