Skip to content

Commit d3d91ea

Browse files
Get the stream and uri factories from the http builder
1 parent 60c2e4b commit d3d91ea

File tree

4 files changed

+69
-15
lines changed

4 files changed

+69
-15
lines changed

lib/Gitlab/Api/AbstractApi.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Gitlab\Exception\RuntimeException;
77
use Gitlab\HttpClient\Message\ResponseMediator;
88
use Gitlab\HttpClient\Util\QueryStringBuilder;
9-
use Http\Discovery\StreamFactoryDiscovery;
109
use Http\Message\MultipartStream\MultipartStreamBuilder;
1110
use Http\Message\StreamFactory;
1211
use Psr\Http\Message\ResponseInterface;
@@ -38,14 +37,20 @@ abstract class AbstractApi implements ApiInterface
3837

3938
/**
4039
* @param Client $client
41-
* @param StreamFactory|null $streamFactory
40+
* @param StreamFactory|null $streamFactory @deprecated since version 9.18 and will be removed in 10.0.
4241
*
4342
* @return void
4443
*/
4544
public function __construct(Client $client, StreamFactory $streamFactory = null)
4645
{
4746
$this->client = $client;
48-
$this->streamFactory = null === $streamFactory ? StreamFactoryDiscovery::find() : $streamFactory;
47+
48+
if (null === $streamFactory) {
49+
$this->streamFactory = $client->getStreamFactory();
50+
} else {
51+
@trigger_error(sprintf('The %s() method\'s $streamFactory parameter is deprecated since version 9.18 and will be removed in 10.0.', __METHOD__), E_USER_DEPRECATED);
52+
$this->streamFactory = $streamFactory;
53+
}
4954
}
5055

5156
/**

lib/Gitlab/Client.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Http\Client\Common\Plugin\HeaderDefaultsPlugin;
1515
use Http\Client\Common\Plugin\HistoryPlugin;
1616
use Http\Client\Common\Plugin\RedirectPlugin;
17+
use Http\Message\StreamFactory;
1718
use Http\Client\HttpClient;
18-
use Http\Discovery\UriFactoryDiscovery;
1919
use Psr\Http\Message\ResponseInterface;
2020

2121
/**
@@ -483,8 +483,10 @@ public function authenticate($token, $authMethod = null, $sudo = null)
483483
*/
484484
public function setUrl($url)
485485
{
486+
$uri = $this->getHttpClientBuilder()->getUriFactory()->createUri($url);
487+
486488
$this->getHttpClientBuilder()->removePlugin(AddHostPlugin::class);
487-
$this->getHttpClientBuilder()->addPlugin(new AddHostPlugin(UriFactoryDiscovery::find()->createUri($url)));
489+
$this->getHttpClientBuilder()->addPlugin(new AddHostPlugin($uri));
488490

489491
return $this;
490492
}
@@ -535,6 +537,16 @@ public function getHttpClient()
535537
return $this->getHttpClientBuilder()->getHttpClient();
536538
}
537539

540+
/**
541+
* Get the stream factory.
542+
*
543+
* @return StreamFactory
544+
*/
545+
public function getStreamFactory()
546+
{
547+
return $this->getHttpClientBuilder()->getStreamFactory();
548+
}
549+
538550
/**
539551
* Get the HTTP client builder.
540552
*

lib/Gitlab/HttpClient/Builder.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
use Http\Discovery\HttpClientDiscovery;
1212
use Http\Discovery\MessageFactoryDiscovery;
1313
use Http\Discovery\StreamFactoryDiscovery;
14+
use Http\Discovery\UriFactoryDiscovery;
1415
use Http\Message\RequestFactory;
1516
use Http\Message\StreamFactory;
17+
use Http\Message\UriFactory;
1618
use Psr\Cache\CacheItemPoolInterface;
1719

1820
/**
@@ -46,6 +48,13 @@ class Builder
4648
*/
4749
private $streamFactory;
4850

51+
/**
52+
* The URI factory.
53+
*
54+
* @var UriFactory
55+
*/
56+
private $uriFactory;
57+
4958
/**
5059
* The currently registered plugins.
5160
*
@@ -75,17 +84,20 @@ class Builder
7584
* @param HttpClient|null $httpClient
7685
* @param RequestFactory|null $requestFactory
7786
* @param StreamFactory|null $streamFactory
87+
* @param UriFactory|null $uriFactory
7888
*
7989
* @return void
8090
*/
8191
public function __construct(
8292
HttpClient $httpClient = null,
8393
RequestFactory $requestFactory = null,
84-
StreamFactory $streamFactory = null
94+
StreamFactory $streamFactory = null,
95+
UriFactory $uriFactory = null
8596
) {
8697
$this->httpClient = null === $httpClient ? HttpClientDiscovery::find() : $httpClient;
8798
$this->requestFactory = null === $requestFactory ? MessageFactoryDiscovery::find() : $requestFactory;
8899
$this->streamFactory = null === $streamFactory ? StreamFactoryDiscovery::find() : $streamFactory;
100+
$this->uriFactory = null === $uriFactory ? UriFactoryDiscovery::find() : $uriFactory;
89101
}
90102

91103
/**
@@ -108,6 +120,36 @@ public function getHttpClient()
108120
return $this->pluginClient;
109121
}
110122

123+
/**
124+
* Get the request factory.
125+
*
126+
* @return RequestFactory
127+
*/
128+
public function getRequestFactory()
129+
{
130+
return $this->requestFactory;
131+
}
132+
133+
/**
134+
* Get the stream factory.
135+
*
136+
* @return StreamFactory
137+
*/
138+
public function getStreamFactory()
139+
{
140+
return $this->streamFactory;
141+
}
142+
143+
/**
144+
* Get the URI factory.
145+
*
146+
* @return UriFactory
147+
*/
148+
public function getUriFactory()
149+
{
150+
return $this->uriFactory;
151+
}
152+
111153
/**
112154
* Add a new plugin to the end of the plugin chain.
113155
*

phpstan-baseline.neon

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\StreamFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
5-
count: 1
6-
path: lib/Gitlab/Api/AbstractApi.php
7-
83
-
94
message: "#^Fetching deprecated class constant AUTH_URL_TOKEN of class Gitlab\\\\Client\\:\nsince version 9\\.18 and will be removed in 10\\.0\\.$#"
105
count: 2
116
path: lib/Gitlab/Client.php
127

138
-
14-
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\UriFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
9+
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\MessageFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
1510
count: 1
16-
path: lib/Gitlab/Client.php
11+
path: lib/Gitlab/HttpClient/Builder.php
1712

1813
-
19-
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\MessageFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
14+
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\StreamFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
2015
count: 1
2116
path: lib/Gitlab/HttpClient/Builder.php
2217

2318
-
24-
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\StreamFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
19+
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\UriFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
2520
count: 1
2621
path: lib/Gitlab/HttpClient/Builder.php
2722

0 commit comments

Comments
 (0)