Skip to content

Commit bed01f4

Browse files
[HttpClient] Replace a few classes and methods occurrences by their source code link
1 parent 3e76637 commit bed01f4

File tree

1 file changed

+55
-38
lines changed

1 file changed

+55
-38
lines changed

http_client.rst

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ original HTTP client::
739739

740740
$client = new RetryableHttpClient(HttpClient::create());
741741

742-
The ``RetryableHttpClient`` uses a
742+
The :class:`Symfony\\Component\\HttpClient\\RetryableHttpClient` uses a
743743
:class:`Symfony\\Component\\HttpClient\\Retry\\RetryStrategyInterface` to
744744
decide if the request should be retried, and to define the waiting time between
745745
each retry.
@@ -777,7 +777,8 @@ called when new data is uploaded or downloaded and at least once per second::
777777
]);
778778

779779
Any exceptions thrown from the callback will be wrapped in an instance of
780-
``TransportExceptionInterface`` and will abort the request.
780+
:class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
781+
and will abort the request.
781782

782783
HTTPS Certificates
783784
~~~~~~~~~~~~~~~~~~
@@ -858,9 +859,10 @@ This component supports both the native PHP streams and cURL to make the HTTP
858859
requests. Although both are interchangeable and provide the same features,
859860
including concurrent requests, HTTP/2 is only supported when using cURL.
860861

861-
``HttpClient::create()`` selects the cURL transport if the `cURL PHP extension`_
862-
is enabled and falls back to PHP streams otherwise. If you prefer to select
863-
the transport explicitly, use the following classes to create the client::
862+
The ``create()`` method of :class:`Symfony\\Component\\HttpClient\\HttpClient`
863+
selects the cURL transport if the `cURL PHP extension`_ is enabled and falls
864+
back to PHP streams otherwise. If you prefer to select the transport
865+
explicitly, use the following classes to create the client::
864866

865867
use Symfony\Component\HttpClient\CurlHttpClient;
866868
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -1041,8 +1043,9 @@ following methods::
10411043
Streaming Responses
10421044
~~~~~~~~~~~~~~~~~~~
10431045

1044-
Call the ``stream()`` method of the HTTP client to get *chunks* of the
1045-
response sequentially instead of waiting for the entire response::
1046+
Call the ``stream()`` method of :class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface`
1047+
to get *chunks* of the response sequentially instead of waiting for the
1048+
entire response::
10461049

10471050
$url = 'https://releases.ubuntu.com/18.04.1/ubuntu-18.04.1-desktop-amd64.iso';
10481051
$response = $client->request('GET', $url);
@@ -1072,8 +1075,7 @@ Canceling Responses
10721075

10731076
To abort a request (e.g. because it didn't complete in due time, or you want to
10741077
fetch only the first bytes of the response, etc.), you can either use the
1075-
``cancel()`` method of
1076-
:class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`::
1078+
``cancel()`` method of :class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`::
10771079

10781080
$response->cancel();
10791081

@@ -1191,10 +1193,12 @@ If you look again at the snippet above, responses are read in requests' order.
11911193
But maybe the 2nd response came back before the 1st? Fully asynchronous operations
11921194
require being able to deal with the responses in whatever order they come back.
11931195

1194-
In order to do so, the ``stream()`` method of HTTP clients accepts a list of
1195-
responses to monitor. As mentioned :ref:`previously <http-client-streaming-responses>`,
1196-
this method yields response chunks as they arrive from the network. By replacing
1197-
the "foreach" in the snippet with this one, the code becomes fully async::
1196+
In order to do so, the ``stream()`` method of
1197+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface` accepts a list of
1198+
responses to monitor. As mentioned
1199+
:ref:`previously <http-client-streaming-responses>`, this method yields response
1200+
chunks as they arrive from the network. By replacing the "foreach" in the
1201+
snippet with this one, the code becomes fully async::
11981202

11991203
foreach ($client->stream($responses) as $response => $chunk) {
12001204
if ($chunk->isFirst()) {
@@ -1331,7 +1335,8 @@ installed in your application::
13311335
// this won't hit the network if the resource is already in the cache
13321336
$response = $client->request('GET', 'https://example.com/cacheable-resource');
13331337

1334-
``CachingHttpClient`` accepts a third argument to set the options of the ``HttpCache``.
1338+
:class:`Symfony\\Component\\HttpClient\\CachingHttpClient`` accepts a third argument
1339+
to set the options of the :class:`Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache`.
13351340

13361341
Consuming Server-Sent Events
13371342
----------------------------
@@ -1497,8 +1502,8 @@ it. As such, you should not use it in newly written code. The component is still
14971502
interoperable with libraries that require it thanks to the
14981503
:class:`Symfony\\Component\\HttpClient\\HttplugClient` class. Similarly to
14991504
:class:`Symfony\\Component\\HttpClient\\Psr18Client` implementing relevant parts of PSR-17,
1500-
``HttplugClient`` also implements the factory methods defined in the related
1501-
``php-http/message-factory`` package.
1505+
:class:`Symfony\\Component\\HttpClient\\HttplugClient` also implements the factory methods
1506+
defined in the related ``php-http/message-factory`` package.
15021507

15031508
.. code-block:: terminal
15041509
@@ -1529,15 +1534,16 @@ that requires HTTPlug dependencies::
15291534
// [...]
15301535
}
15311536

1532-
Because ``HttplugClient`` implements the three interfaces, you can use it this way::
1537+
Because :class:`Symfony\\Component\\HttpClient\\HttplugClient` implements the
1538+
three interfaces,you can use it this way::
15331539

15341540
use Symfony\Component\HttpClient\HttplugClient;
15351541

15361542
$httpClient = new HttplugClient();
15371543
$apiClient = new SomeSdk($httpClient, $httpClient, $httpClient);
15381544

1539-
If you'd like to work with promises, ``HttplugClient`` also implements the
1540-
``HttpAsyncClient`` interface. To use it, you need to install the
1545+
If you'd like to work with promises, :class:`Symfony\\Component\\HttpClient\\HttplugClient`
1546+
also implements the ``HttpAsyncClient`` interface. To use it, you need to install the
15411547
``guzzlehttp/promises`` package:
15421548

15431549
.. code-block:: terminal
@@ -1717,20 +1723,24 @@ external service. By not making actual HTTP requests there is no need to worry a
17171723
the service being online or the request changing state, for example deleting
17181724
a resource.
17191725

1720-
``MockHttpClient`` implements the ``HttpClientInterface``, just like any actual
1721-
HTTP client in this component. When you type-hint with ``HttpClientInterface``
1722-
your code will accept the real client outside tests, while replacing it with
1723-
``MockHttpClient`` in the test.
1726+
:class:`Symfony\\Component\\HttpClient\\MockHttpClient` implements the
1727+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface`, just like any actual
1728+
HTTP client in this component. When you type-hint with
1729+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface` your code will accept
1730+
the real client outside tests, while replacing it with
1731+
:class:`Symfony\\Component\\HttpClient\\MockHttpClient` in the test.
17241732

1725-
When the ``request`` method is used on ``MockHttpClient``, it will respond with
1726-
the supplied ``MockResponse``. There are a few ways to use it, as described
1727-
below.
1733+
When the ``request`` method is used on :class:`Symfony\\Component\\HttpClient\\MockHttpClient`,
1734+
it will respond with the supplied
1735+
:class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`. There are a few ways to use
1736+
it, as described below.
17281737

17291738
HTTP Client and Responses
17301739
~~~~~~~~~~~~~~~~~~~~~~~~~
17311740

1732-
The first way of using ``MockHttpClient`` is to pass a list of responses to its
1733-
constructor. These will be yielded in order when requests are made::
1741+
The first way of using :class:`Symfony\\Component\\HttpClient\\MockHttpClient`
1742+
is to pass a list of responses to its constructor. These will be yielded
1743+
in order when requests are made::
17341744

17351745
use Symfony\Component\HttpClient\MockHttpClient;
17361746
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1745,8 +1755,8 @@ constructor. These will be yielded in order when requests are made::
17451755
$response1 = $client->request('...'); // returns $responses[0]
17461756
$response2 = $client->request('...'); // returns $responses[1]
17471757

1748-
Another way of using ``MockHttpClient`` is to pass a callback that generates the
1749-
responses dynamically when it's called::
1758+
Another way of using :class:`Symfony\\Component\\HttpClient\\MockHttpClient` is to
1759+
pass a callback that generates the responses dynamically when it's called::
17501760

17511761
use Symfony\Component\HttpClient\MockHttpClient;
17521762
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1761,7 +1771,9 @@ responses dynamically when it's called::
17611771
.. tip::
17621772

17631773
Instead of using the first argument, you can also set the (list of)
1764-
responses or callbacks using the ``setResponseFactory()`` method::
1774+
responses or callbacks using the
1775+
:method:`Symfony\\Component\\HttpClient\\MockHttpClient::setResponseFactory`
1776+
method::
17651777

17661778
$responses = [
17671779
new MockResponse($body1, $info1),
@@ -1773,7 +1785,8 @@ responses dynamically when it's called::
17731785

17741786
.. versionadded:: 5.4
17751787

1776-
The ``setResponseFactory()`` method was introduced in Symfony 5.4.
1788+
The :method:`Symfony\\Component\\HttpClient\\MockHttpClient::setResponseFactory`
1789+
method was introduced in Symfony 5.4.
17771790

17781791
If you need to test responses with HTTP status codes different than 200,
17791792
define the ``http_code`` option::
@@ -1789,10 +1802,12 @@ define the ``http_code`` option::
17891802
$response = $client->request('...');
17901803

17911804
The responses provided to the mock client don't have to be instances of
1792-
``MockResponse``. Any class implementing ``ResponseInterface`` will work (e.g.
1793-
``$this->createMock(ResponseInterface::class)``).
1805+
:class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`. Any class
1806+
implementing :class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`
1807+
will work (e.g. ``$this->createMock(ResponseInterface::class)``).
17941808

1795-
However, using ``MockResponse`` allows simulating chunked responses and timeouts::
1809+
However, using :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`
1810+
allows simulating chunked responses and timeouts::
17961811

17971812
$body = function () {
17981813
yield 'hello';
@@ -1884,7 +1899,8 @@ Then configure Symfony to use your callback:
18841899
Testing Request Data
18851900
~~~~~~~~~~~~~~~~~~~~
18861901

1887-
The ``MockResponse`` class comes with some helper methods to test the request:
1902+
The :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse` class comes
1903+
with some helper methods to test the request:
18881904

18891905
* ``getRequestMethod()`` - returns the HTTP method;
18901906
* ``getRequestUrl()`` - returns the URL the request would be sent to;
@@ -1893,8 +1909,9 @@ The ``MockResponse`` class comes with some helper methods to test the request:
18931909

18941910
.. versionadded:: 5.2
18951911

1896-
The ``getRequestMethod()`` and ``getRequestUrl()`` methods were introduced
1897-
in Symfony 5.2.
1912+
The :method:`Symfony\\Component\\HttpClient\\Response\\MockResponse::getRequestMethod`
1913+
and :method:`Symfony\\Component\\HttpClient\\Response\\MockResponse::getRequestUrl`
1914+
methods were introduced in Symfony 5.2.
18981915

18991916
Usage example::
19001917

0 commit comments

Comments
 (0)