Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit8ef49cf

Browse files
feature#41161 [HttpClient] AddDecoratorTrait to ease writing simple decorators (nicolas-grekas)
This PR was merged into the 5.3-dev branch.Discussion----------[HttpClient] Add `DecoratorTrait` to ease writing simple decorators| Q | A| ------------- | ---| Branch? | 5.x| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets | -| License | MIT| Doc PR | -Commits-------4682170 [HttpClient] Add `DecoratorTrait` to ease writing simple decorators
2 parents252ee39 +4682170 commit8ef49cf

File tree

3 files changed

+60
-18
lines changed

3 files changed

+60
-18
lines changed

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
useSymfony\Component\HttpClient\Response\AsyncResponse;
1515
useSymfony\Component\HttpClient\Response\ResponseStream;
16-
useSymfony\Contracts\HttpClient\HttpClientInterface;
1716
useSymfony\Contracts\HttpClient\ResponseInterface;
1817
useSymfony\Contracts\HttpClient\ResponseStreamInterface;
1918

@@ -24,12 +23,7 @@
2423
*/
2524
trait AsyncDecoratorTrait
2625
{
27-
private$client;
28-
29-
publicfunction__construct(HttpClientInterface$client =null)
30-
{
31-
$this->client =$client ?? HttpClient::create();
32-
}
26+
use DecoratorTrait;
3327

3428
/**
3529
* {@inheritdoc}
@@ -51,15 +45,4 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
5145

5246
returnnewResponseStream(AsyncResponse::stream($responses,$timeout,static::class));
5347
}
54-
55-
/**
56-
* {@inheritdoc}
57-
*/
58-
publicfunctionwithOptions(array$options):self
59-
{
60-
$clone =clone$this;
61-
$clone->client =$this->client->withOptions($options);
62-
63-
return$clone;
64-
}
6548
}

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

Lines 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
-----
Lines 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+
namespaceSymfony\Component\HttpClient;
13+
14+
useSymfony\Contracts\HttpClient\HttpClientInterface;
15+
useSymfony\Contracts\HttpClient\ResponseInterface;
16+
useSymfony\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+
publicfunction__construct(HttpClientInterface$client =null)
28+
{
29+
$this->client =$client ?? HttpClient::create();
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
publicfunctionrequest(string$method,string$url,array$options = []):ResponseInterface
36+
{
37+
return$this->client->request($method,$url,$options);
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
publicfunctionstream($responses,float$timeout =null):ResponseStreamInterface
44+
{
45+
return$this->client->stream($responses,$timeout);
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
publicfunctionwithOptions(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)

[8]ページ先頭

©2009-2025 Movatter.jp