# ServerRequestCreator

> Creates PSR-7 server requests from PHP globals.

[API reference](/docs/api/index.md) › [PSR bridge](/docs/extensions/psr-bridge/reference/index.md) › [creator](/docs/extensions/psr-bridge/reference/creator/index.md) › ServerRequestCreator

| final class | `yii2\extensions\psrbridge\creator\ServerRequestCreator` |
| --- | --- |
| Source | [`src/creator/ServerRequestCreator.php`](https://github.com/yii2-extensions/psr-bridge/blob/main/src/creator/ServerRequestCreator.php#L32) |

Creates PSR-7 server requests from PHP globals.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a new instance of the [`ServerRequestCreator`](/docs/extensions/psr-bridge/reference/creator/serverrequestcreator/index.md) class. | `ServerRequestCreator` |
| [`createFromGlobals()`](#method-createFromGlobals) | Builds a PSR request from the current SAPI globals and attaches a `php://input` body when available. | `ServerRequestCreator` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(Psr\Http\Message\ServerRequestFactoryInterface $serverRequestFactory, Psr\Http\Message\StreamFactoryInterface $streamFactory, Psr\Http\Message\UploadedFileFactoryInterface $uploadedFileFactory)
```

Creates a new instance of the [`ServerRequestCreator`](/docs/extensions/psr-bridge/reference/creator/serverrequestcreator/index.md) class.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$serverRequestFactory` | `Psr\Http\Message\ServerRequestFactoryInterface` | Factory to create server requests. |
| `$streamFactory` | `Psr\Http\Message\StreamFactoryInterface` | Factory to create streams. |
| `$uploadedFileFactory` | `Psr\Http\Message\UploadedFileFactoryInterface` | Factory to create uploaded files. |

### createFromGlobals() <span id="method-createFromGlobals"></span>

```php
public function createFromGlobals(): Psr\Http\Message\ServerRequestInterface
```

Builds a PSR request from the current SAPI globals and attaches a `php://input` body when available.

Copies `HTTP_*` and CGI content headers, server parameters, cookies, query parameters, and nested uploads.
Nonempty `$_POST`, and empty `$_POST` for POST form or multipart requests, become the parsed body. Other
bodies stay `null` for configured parsers or the URL-encoded fallback. Input stream failures leave the
factory's original body unchanged.

**Returns**

`Psr\Http\Message\ServerRequestInterface`: Request created from the current globals.