Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4297221

Browse filesBrowse files
[HttpClient] Add DecoratorTrait to ease writing simple decorators
1 parent 90ab9ed commit 4297221
Copy full SHA for 4297221

File tree

3 files changed

+60
-17
lines changed
Filter options

3 files changed

+60
-17
lines changed

‎src/Symfony/Component/HttpClient/AsyncDecoratorTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/AsyncDecoratorTrait.php
+1-17Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@
2424
*/
2525
trait AsyncDecoratorTrait
2626
{
27-
private $client;
28-
29-
public function __construct(HttpClientInterface $client = null)
30-
{
31-
$this->client = $client ?? HttpClient::create();
32-
}
27+
use DecoratorTrait;
3328

3429
/**
3530
* {@inheritdoc}
@@ -51,15 +46,4 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
5146

5247
return new ResponseStream(AsyncResponse::stream($responses, $timeout, static::class));
5348
}
54-
55-
/**
56-
* {@inheritdoc}
57-
*/
58-
public function withOptions(array $options): self
59-
{
60-
$clone = clone $this;
61-
$clone->client = $this->client->withOptions($options);
62-
63-
return $clone;
64-
}
6549
}

‎src/Symfony/Component/HttpClient/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Implement `HttpClientInterface::withOptions()` from `symfony/contracts` v2.4
8+
* Add `DecoratorTrait` to ease writing simple decorators
89

910
5.2.0
1011
-----
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\HttpClient;
13+
14+
use Symfony\Contracts\HttpClient\HttpClientInterface;
15+
use Symfony\Contracts\HttpClient\ResponseInterface;
16+
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
17+
18+
/**
19+
* Eases with writing decorators.
20+
*
21+
* @author Nicolas Grekas <p@tchwork.com>
22+
*/
23+
trait DecoratorTrait
24+
{
25+
private $client;
26+
27+
public function __construct(HttpClientInterface $client = null)
28+
{
29+
$this->client = $client ?? HttpClient::create();
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function request(string $method, string $url, array $options = []): ResponseInterface
36+
{
37+
return $this->client->request($method, $url, $options);
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function stream($responses, float $timeout = null): ResponseStreamInterface
44+
{
45+
return $this->client->stream($responses, $timeout);
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
public function withOptions(array $options): self
52+
{
53+
$clone = clone $this;
54+
$clone->client = $this->client->withOptions($options);
55+
56+
return $clone;
57+
}
58+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.