Skip to content

Commit ad85226

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: [HttpClient] Replace a few classes and methods occurrences by their source code link
2 parents 599922c + 45bf439 commit ad85226

File tree

1 file changed

+50
-35
lines changed

1 file changed

+50
-35
lines changed

http_client.rst

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ original HTTP client::
724724

725725
$client = new RetryableHttpClient(HttpClient::create());
726726

727-
The ``RetryableHttpClient`` uses a
727+
The :class:`Symfony\\Component\\HttpClient\\RetryableHttpClient` uses a
728728
:class:`Symfony\\Component\\HttpClient\\Retry\\RetryStrategyInterface` to
729729
decide if the request should be retried, and to define the waiting time between
730730
each retry.
@@ -762,7 +762,8 @@ called when new data is uploaded or downloaded and at least once per second::
762762
]);
763763

764764
Any exceptions thrown from the callback will be wrapped in an instance of
765-
``TransportExceptionInterface`` and will abort the request.
765+
:class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
766+
and will abort the request.
766767

767768
HTTPS Certificates
768769
~~~~~~~~~~~~~~~~~~
@@ -835,9 +836,10 @@ This component supports both the native PHP streams and cURL to make the HTTP
835836
requests. Although both are interchangeable and provide the same features,
836837
including concurrent requests, HTTP/2 is only supported when using cURL.
837838

838-
``HttpClient::create()`` selects the cURL transport if the `cURL PHP extension`_
839-
is enabled and falls back to PHP streams otherwise. If you prefer to select
840-
the transport explicitly, use the following classes to create the client::
839+
The :method:`Symfony\\Component\\HttpClient\\HttpClient::create` method
840+
selects the cURL transport if the `cURL PHP extension`_ is enabled and falls
841+
back to PHP streams otherwise. If you prefer to select the transport
842+
explicitly, use the following classes to create the client::
841843

842844
use Symfony\Component\HttpClient\CurlHttpClient;
843845
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -1008,8 +1010,9 @@ following methods::
10081010
Streaming Responses
10091011
~~~~~~~~~~~~~~~~~~~
10101012

1011-
Call the ``stream()`` method of the HTTP client to get *chunks* of the
1012-
response sequentially instead of waiting for the entire response::
1013+
Call the :method:`Symfony\\Contracts\\HttpClient\\HttpClientInterface::stream`
1014+
method to get *chunks* of the response sequentially instead of waiting for the
1015+
entire response::
10131016

10141017
$url = 'https://releases.ubuntu.com/18.04.1/ubuntu-18.04.1-desktop-amd64.iso';
10151018
$response = $client->request('GET', $url);
@@ -1039,8 +1042,7 @@ Canceling Responses
10391042

10401043
To abort a request (e.g. because it didn't complete in due time, or you want to
10411044
fetch only the first bytes of the response, etc.), you can either use the
1042-
``cancel()`` method of
1043-
:class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`::
1045+
:method:`Symfony\\Contracts\\HttpClient\\ResponseInterface::cancel`::
10441046

10451047
$response->cancel();
10461048

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

1161-
In order to do so, the ``stream()`` method of HTTP clients accepts a list of
1162-
responses to monitor. As mentioned :ref:`previously <http-client-streaming-responses>`,
1163-
this method yields response chunks as they arrive from the network. By replacing
1164-
the "foreach" in the snippet with this one, the code becomes fully async::
1163+
In order to do so, the
1164+
:method:`Symfony\\Contracts\\HttpClient\\HttpClientInterface::stream`
1165+
accepts a list of responses to monitor. As mentioned
1166+
:ref:`previously <http-client-streaming-responses>`, this method yields response
1167+
chunks as they arrive from the network. By replacing the "foreach" in the
1168+
snippet with this one, the code becomes fully async::
11651169

11661170
foreach ($client->stream($responses) as $response => $chunk) {
11671171
if ($chunk->isFirst()) {
@@ -1300,7 +1304,8 @@ installed in your application::
13001304
// this won't hit the network if the resource is already in the cache
13011305
$response = $client->request('GET', 'https://example.com/cacheable-resource');
13021306

1303-
``CachingHttpClient`` accepts a third argument to set the options of the ``HttpCache``.
1307+
:class:`Symfony\\Component\\HttpClient\\CachingHttpClient`` accepts a third argument
1308+
to set the options of the :class:`Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache`.
13041309

13051310
Consuming Server-Sent Events
13061311
----------------------------
@@ -1479,8 +1484,8 @@ it. As such, you should not use it in newly written code. The component is still
14791484
interoperable with libraries that require it thanks to the
14801485
:class:`Symfony\\Component\\HttpClient\\HttplugClient` class. Similarly to
14811486
:class:`Symfony\\Component\\HttpClient\\Psr18Client` implementing relevant parts of PSR-17,
1482-
``HttplugClient`` also implements the factory methods defined in the related
1483-
``php-http/message-factory`` package.
1487+
:class:`Symfony\\Component\\HttpClient\\HttplugClient` also implements the factory methods
1488+
defined in the related ``php-http/message-factory`` package.
14841489

14851490
.. code-block:: terminal
14861491
@@ -1511,15 +1516,16 @@ that requires HTTPlug dependencies::
15111516
// [...]
15121517
}
15131518

1514-
Because ``HttplugClient`` implements the three interfaces, you can use it this way::
1519+
Because :class:`Symfony\\Component\\HttpClient\\HttplugClient` implements the
1520+
three interfaces,you can use it this way::
15151521

15161522
use Symfony\Component\HttpClient\HttplugClient;
15171523

15181524
$httpClient = new HttplugClient();
15191525
$apiClient = new SomeSdk($httpClient, $httpClient, $httpClient);
15201526

1521-
If you'd like to work with promises, ``HttplugClient`` also implements the
1522-
``HttpAsyncClient`` interface. To use it, you need to install the
1527+
If you'd like to work with promises, :class:`Symfony\\Component\\HttpClient\\HttplugClient`
1528+
also implements the ``HttpAsyncClient`` interface. To use it, you need to install the
15231529
``guzzlehttp/promises`` package:
15241530

15251531
.. code-block:: terminal
@@ -1712,20 +1718,24 @@ external service. By not making actual HTTP requests there is no need to worry a
17121718
the service being online or the request changing state, for example deleting
17131719
a resource.
17141720

1715-
``MockHttpClient`` implements the ``HttpClientInterface``, just like any actual
1716-
HTTP client in this component. When you type-hint with ``HttpClientInterface``
1717-
your code will accept the real client outside tests, while replacing it with
1718-
``MockHttpClient`` in the test.
1721+
:class:`Symfony\\Component\\HttpClient\\MockHttpClient` implements the
1722+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface`, just like any actual
1723+
HTTP client in this component. When you type-hint with
1724+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface` your code will accept
1725+
the real client outside tests, while replacing it with
1726+
:class:`Symfony\\Component\\HttpClient\\MockHttpClient` in the test.
17191727

1720-
When the ``request`` method is used on ``MockHttpClient``, it will respond with
1721-
the supplied ``MockResponse``. There are a few ways to use it, as described
1722-
below.
1728+
When the ``request`` method is used on :class:`Symfony\\Component\\HttpClient\\MockHttpClient`,
1729+
it will respond with the supplied
1730+
:class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`. There are a few ways to use
1731+
it, as described below.
17231732

17241733
HTTP Client and Responses
17251734
~~~~~~~~~~~~~~~~~~~~~~~~~
17261735

1727-
The first way of using ``MockHttpClient`` is to pass a list of responses to its
1728-
constructor. These will be yielded in order when requests are made::
1736+
The first way of using :class:`Symfony\\Component\\HttpClient\\MockHttpClient`
1737+
is to pass a list of responses to its constructor. These will be yielded
1738+
in order when requests are made::
17291739

17301740
use Symfony\Component\HttpClient\MockHttpClient;
17311741
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1740,8 +1750,8 @@ constructor. These will be yielded in order when requests are made::
17401750
$response1 = $client->request('...'); // returns $responses[0]
17411751
$response2 = $client->request('...'); // returns $responses[1]
17421752

1743-
Another way of using ``MockHttpClient`` is to pass a callback that generates the
1744-
responses dynamically when it's called::
1753+
Another way of using :class:`Symfony\\Component\\HttpClient\\MockHttpClient` is to
1754+
pass a callback that generates the responses dynamically when it's called::
17451755

17461756
use Symfony\Component\HttpClient\MockHttpClient;
17471757
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1778,7 +1788,9 @@ assertions on the request before returning the mocked response::
17781788
.. tip::
17791789

17801790
Instead of using the first argument, you can also set the (list of)
1781-
responses or callbacks using the ``setResponseFactory()`` method::
1791+
responses or callbacks using the
1792+
:method:`Symfony\\Component\\HttpClient\\MockHttpClient::setResponseFactory`
1793+
method::
17821794

17831795
$responses = [
17841796
new MockResponse($body1, $info1),
@@ -1802,10 +1814,12 @@ define the ``http_code`` option::
18021814
$response = $client->request('...');
18031815

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

1808-
However, using ``MockResponse`` allows simulating chunked responses and timeouts::
1821+
However, using :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`
1822+
allows simulating chunked responses and timeouts::
18091823

18101824
$body = function () {
18111825
yield 'hello';
@@ -1893,7 +1907,8 @@ Then configure Symfony to use your callback:
18931907
Testing Request Data
18941908
~~~~~~~~~~~~~~~~~~~~
18951909

1896-
The ``MockResponse`` class comes with some helper methods to test the request:
1910+
The :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse` class comes
1911+
with some helper methods to test the request:
18971912

18981913
* ``getRequestMethod()`` - returns the HTTP method;
18991914
* ``getRequestUrl()`` - returns the URL the request would be sent to;

0 commit comments

Comments
 (0)