summaryrefslogtreecommitdiff
path: root/src/Http/Psr7ServiceProvider.php
blob: d58ee6e91a0139efee4a268a3518a9d9fa0845cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

namespace Engelsystem\Http;

use Engelsystem\Container\ServiceProvider;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;

class Psr7ServiceProvider extends ServiceProvider
{
    public function register()
    {
        $psr17Factory = Psr17Factory::class;

        foreach (
            [
                'psr7.factory.request',
                ServerRequestFactoryInterface::class,
                'psr7.factory.response',
                ResponseFactoryInterface::class,
                'psr7.factory.upload',
                UploadedFileFactoryInterface::class,
                'psr7.factory.stream',
                StreamFactoryInterface::class,
            ] as $alias
        ) {
            $this->app->bind($alias, $psr17Factory);
        }

        $this->app->bind('psr7.factory', PsrHttpFactory::class);
        $this->app->bind(HttpMessageFactoryInterface::class, PsrHttpFactory::class);

        $this->app->bind('psr7.request', 'request');
        $this->app->bind(ServerRequestInterface::class, 'psr7.request');

        $this->app->bind('psr7.response', 'response');
        $this->app->bind(ResponseInterface::class, 'psr7.response');
    }
}