Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractRequest
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
5 / 5
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 setUri
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getUri
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUriAsString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasUri
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Http;
15
16/**
17 * Abstract HTTP request class
18 *
19 * @category   Pop
20 * @package    Pop\Http
21 * @author     Nick Sagona, III <dev@nolainteractive.com>
22 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
23 * @license    http://www.popphp.org/license     New BSD License
24 * @version    5.0.0
25 */
26abstract class AbstractRequest extends AbstractRequestResponse
27{
28
29    /**
30     * Request URI object
31     * @var ?Uri
32     */
33    protected ?Uri $uri = null;
34
35    /**
36     * Constructor
37     *
38     * Instantiate the request object
39     *
40     * @param  Uri|string|null $uri
41     * @throws Exception
42     */
43    public function __construct(Uri|string|null $uri = null)
44    {
45        if ($uri !== null) {
46            $this->setUri($uri);
47        }
48    }
49
50    /**
51     * Set URI
52     *
53     * @param  Uri|string $uri
54     * @throws Exception
55     * @return AbstractRequest
56     */
57    public function setUri(Uri|string $uri): AbstractRequest
58    {
59        $this->uri = (is_string($uri)) ? new Uri($uri) : $uri;
60        return $this;
61    }
62
63    /**
64     * Get URI
65     *
66     * @return Uri
67     */
68    public function getUri(): Uri
69    {
70        return $this->uri;
71    }
72
73    /**
74     * Get URI as string
75     *
76     * @return string
77     */
78    public function getUriAsString(): string
79    {
80        return (string)$this->uri?->render();
81    }
82
83    /**
84     * Has URI
85     *
86     * @return bool
87     */
88    public function hasUri(): bool
89    {
90        return ($this->uri !== null);
91    }
92
93}