Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3namespace Dynart\Micro;
4
5/**
6 * Represents the HTTP request
7 *
8 * It can be used for getting the information of the HTTP request: the request method (POST, GET, etc.),
9 * the query parameters, the headers, the information that created by the web server, the cookies
10 * and the uploaded files.
11 *
12 * @see UploadedFile
13 */
14interface RequestInterface {
15    /**
16     * Returns with a parameter of the request, uses the $_REQUEST array
17     */
18    public function get(string $name, mixed $default = null): mixed;
19
20    /**
21     * Returns with the information that was created by the web server, uses the $_SERVER array
22     */
23    public function server(string $name, mixed $default = null): mixed;
24
25    /**
26     * Returns the HTTP request method
27     */
28    public function httpMethod(): string;
29
30    /**
31     * Returns with the IP of the client if present, otherwise null
32     *
33     * Important! This value can't be trusted, this is just for hashing/logging purposes.
34     */
35    public function ip(): ?string;
36
37    /**
38     * Sets a request header
39     */
40    public function setHeader(string $name, string $value): void;
41
42    /**
43     * Returns with a request header by name
44     */
45    public function header(string $name, mixed $default = null): mixed;
46
47    /**
48     * Returns with a cookie value by name
49     */
50    public function cookie(string $name, mixed $default = null): mixed;
51
52    /**
53     * Returns with the request body
54     */
55    public function body(): string;
56
57    /**
58     * Sets the request body
59     */
60    public function setBody(string $content): void;
61
62    /**
63     * Returns with the request body as an associative array parsed from JSON
64     *
65     * Throws a MicroException if the JSON is invalid.
66     *
67     * @throws MicroException
68     */
69    public function bodyAsJson(): ?array;
70
71    /**
72     * Returns with the uploaded file by parameter name
73     *
74     * If the parameter not present it will return with a null.
75     * If only one file uploaded it will return with an UploadedFile instance.
76     * If more than one file uploaded it will return with an array.
77     *
78     * @return UploadedFile|UploadedFile[]|null
79     */
80    public function uploadedFile(string $name): UploadedFile|array|null;
81}