Skip to content

Commit 041ab07

Browse files
committed
Create an abstract HTTP transport and extend it in all HTTP transports
1 parent b49e43b commit 041ab07

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Transport\Http;
13+
14+
use Psr\Log\LoggerInterface;
15+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16+
use Symfony\Component\HttpClient\HttpClient;
17+
use Symfony\Component\Mailer\Transport\AbstractTransport;
18+
use Symfony\Contracts\HttpClient\HttpClientInterface;
19+
20+
/**
21+
* @author Victor Bocharsky <victor@symfonycasts.com>
22+
*
23+
* @experimental in 4.3
24+
*/
25+
abstract class AbstractHttpTransport extends AbstractTransport
26+
{
27+
protected $client;
28+
29+
public function __construct(HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
30+
{
31+
$this->client = $client;
32+
if (null === $client) {
33+
if (!class_exists(HttpClient::class)) {
34+
throw new \LogicException(sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__));
35+
}
36+
37+
$this->client = HttpClient::create();
38+
}
39+
40+
parent::__construct($dispatcher, $logger);
41+
}
42+
}

0 commit comments

Comments
 (0)