-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #31650 Create an abstract HTTP transport and extend it in all HTT…
…P transports (bocharsky-bw) This PR was merged into the 4.3 branch. Discussion ---------- Create an abstract HTTP transport and extend it in all HTTP transports | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | no | License | MIT | Doc PR | no Right now when you try to use an HTTP transport e.g. Mailgun w/o HTTP client installed - the error message is: > Attempted to load class "HttpClient" from namespace "Symfony\Component\HttpClient". Did you forget a "use" statement for "Http\Client\HttpClient"? Not clear enough about what to do. After this PR the error message will be: > You cannot use "Symfony\Component\Mailer\Bridge\Mailgun\Http\MailgunTransport" as the HttpClient component is not installed. Try running "composer require symfony/http-client". Actually, we already have a similar check for API: https://github.com/symfony/symfony/blob/2c9a1960a164a857cd551881b580266bc77bdafa/src/Symfony/Component/Mailer/Transport/Http/Api/AbstractApiTransport.php#L37-L44 Commits ------- 3c8d63c Create an abstract HTTP transport and extend it in all HTTP transports
- Loading branch information
Showing
4 changed files
with
51 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Symfony/Component/Mailer/Transport/Http/AbstractHttpTransport.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Transport\Http; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpClient\HttpClient; | ||
use Symfony\Component\Mailer\Transport\AbstractTransport; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
/** | ||
* @author Victor Bocharsky <victor@symfonycasts.com> | ||
* | ||
* @experimental in 4.3 | ||
*/ | ||
abstract class AbstractHttpTransport extends AbstractTransport | ||
{ | ||
protected $client; | ||
|
||
public function __construct(HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null) | ||
{ | ||
$this->client = $client; | ||
if (null === $client) { | ||
if (!class_exists(HttpClient::class)) { | ||
throw new \LogicException(sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__)); | ||
} | ||
|
||
$this->client = HttpClient::create(); | ||
} | ||
|
||
parent::__construct($dispatcher, $logger); | ||
} | ||
} |