Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ServerRequestFactory
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 createServerRequest
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
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 <dev@noladev.com>
8 * @copyright  Copyright (c) 2009-2027 NOLA Interactive, LLC.
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Http\Factory;
16
17use Psr\Http\Message\ServerRequestFactoryInterface;
18use Psr\Http\Message\ServerRequestInterface;
19use Psr\Http\Message\UriInterface;
20use Pop\Http\Server\Request;
21use Pop\Http\Uri;
22
23/**
24 * PSR-17 server request factory class
25 *
26 * @category   Pop
27 * @package    Pop\Http
28 * @author     Nick Sagona, III <dev@noladev.com>
29 * @copyright  Copyright (c) 2009-2027 NOLA Interactive, LLC.
30 * @license    https://www.popphp.org/license     New BSD License
31 * @version    6.0.0
32 */
33class ServerRequestFactory implements ServerRequestFactoryInterface
34{
35
36    /**
37     * Create a new server request - does not read PHP superglobals, per PSR-17
38     *
39     * @param  string              $method
40     * @param  UriInterface|string $uri
41     * @param  array               $serverParams
42     * @return ServerRequestInterface
43     */
44    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
45    {
46        $uriString = ($uri instanceof UriInterface) ? (string)$uri : $uri;
47        $request   = new Request(new Uri($uriString), null, null, false, $serverParams);
48
49        return $request->withMethod($method);
50    }
51
52}