DiscoveryPsr17Factory example

private readonly UploadedFileFactoryInterface $uploadedFileFactory;
    private readonly ResponseFactoryInterface $responseFactory;

    public function __construct(
        ServerRequestFactoryInterface $serverRequestFactory = null,
        StreamFactoryInterface $streamFactory = null,
        UploadedFileFactoryInterface $uploadedFileFactory = null,
        ResponseFactoryInterface $responseFactory = null,
    ) {
        if (null === $serverRequestFactory || null === $streamFactory || null === $uploadedFileFactory || null === $responseFactory) {
            $psr17Factory = match (true) {
                class_exists(DiscoveryPsr17Factory::class) => new DiscoveryPsr17Factory(),
                class_exists(NyholmPsr17Factory::class) => new NyholmPsr17Factory(),
                default => throw new \LogicException(sprintf('You cannot use the "%s" as no PSR-17 factories have been provided. Try running "composer require php-http/discovery psr/http-factory-implementation:*".', self::class)),
            };

            $serverRequestFactory ??= $psr17Factory;
            $streamFactory ??= $psr17Factory;
            $uploadedFileFactory ??= $psr17Factory;
            $responseFactory ??= $psr17Factory;
        }

        $this->serverRequestFactory = $serverRequestFactory;
        
Home | Imprint | This part of the site doesn't use cookies.