astehlik/typo3-extension-mediaoembed

View on GitHub
Classes/Request/HttpClient/HttpClientFactory.php

Summary

Maintainability
A
0 mins
Test Coverage
B
85%
<?php

declare(strict_types=1);

namespace Sto\Mediaoembed\Request\HttpClient;

use Psr\Container\ContainerInterface;
use Sto\Mediaoembed\Content\Configuration;

class HttpClientFactory
{
    private ContainerInterface $container;

    public function __construct(
        ContainerInterface $container,
    ) {
        $this->container = $container;
    }

    public function getHttpClient(Configuration $configuration): HttpClientInterface
    {
        $httpClientClass = $configuration->getHttpClientClass();

        if ($httpClientClass === '') {
            // If nothing is configured we fallback to our default client.
            $httpClientClass = GetUrlHttpClient::class;
        }

        return $this->container->get($httpClientClass);
    }
}