Skip to content

Commit ea53c03

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

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

http_client.rst

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ method to retrieve a new instance of the client with new default options::
148148

149149
.. versionadded:: 5.3
150150

151-
The ``withOptions()`` method was introduced in Symfony 5.3.
151+
The :method:`Symfony\\Contracts\\HttpClient\\HttpClientInterface::withOptions`
152+
method was introduced in Symfony 5.3.
152153

153154
Some options are described in this guide:
154155

@@ -739,7 +740,7 @@ original HTTP client::
739740

740741
$client = new RetryableHttpClient(HttpClient::create());
741742

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

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

782784
HTTPS Certificates
783785
~~~~~~~~~~~~~~~~~~
@@ -858,9 +860,10 @@ This component supports both the native PHP streams and cURL to make the HTTP
858860
requests. Although both are interchangeable and provide the same features,
859861
including concurrent requests, HTTP/2 is only supported when using cURL.
860862

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::
863+
The ``create()`` method of :class:`Symfony\\Component\\HttpClient\\HttpClient`
864+
selects the cURL transport if the `cURL PHP extension`_ is enabled and falls
865+
back to PHP streams otherwise. If you prefer to select the transport
866+
explicitly, use the following classes to create the client::
864867

865868
use Symfony\Component\HttpClient\CurlHttpClient;
866869
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -1041,8 +1044,9 @@ following methods::
10411044
Streaming Responses
10421045
~~~~~~~~~~~~~~~~~~~
10431046

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

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

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

10781081
$response->cancel();
10791082

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

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

11991204
foreach ($client->stream($responses) as $response => $chunk) {
12001205
if ($chunk->isFirst()) {
@@ -1331,7 +1336,8 @@ installed in your application::
13311336
// this won't hit the network if the resource is already in the cache
13321337
$response = $client->request('GET', 'https://example.com/cacheable-resource');
13331338

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

13361342
Consuming Server-Sent Events
13371343
----------------------------
@@ -1497,8 +1503,8 @@ it. As such, you should not use it in newly written code. The component is still
14971503
interoperable with libraries that require it thanks to the
14981504
:class:`Symfony\\Component\\HttpClient\\HttplugClient` class. Similarly to
14991505
: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.
1506+
:class:`Symfony\\Component\\HttpClient\\HttplugClient` also implements the factory methods
1507+
defined in the related ``php-http/message-factory`` package.
15021508

15031509
.. code-block:: terminal
15041510
@@ -1529,15 +1535,16 @@ that requires HTTPlug dependencies::
15291535
// [...]
15301536
}
15311537

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

15341541
use Symfony\Component\HttpClient\HttplugClient;
15351542

15361543
$httpClient = new HttplugClient();
15371544
$apiClient = new SomeSdk($httpClient, $httpClient, $httpClient);
15381545

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

15431550
.. code-block:: terminal
@@ -1717,20 +1724,24 @@ external service. By not making actual HTTP requests there is no need to worry a
17171724
the service being online or the request changing state, for example deleting
17181725
a resource.
17191726

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.
1727+
:class:`Symfony\\Component\\HttpClient\\MockHttpClient` implements the
1728+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface`, just like any actual
1729+
HTTP client in this component. When you type-hint with
1730+
:class:`Symfony\\Contracts\\HttpClient\\HttpClientInterface` your code will accept
1731+
the real client outside tests, while replacing it with
1732+
:class:`Symfony\\Component\\HttpClient\\MockHttpClient` in the test.
17241733

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.
1734+
When the ``request`` method is used on :class:`Symfony\\Component\\HttpClient\\MockHttpClient`,
1735+
it will respond with the supplied
1736+
:class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`. There are a few ways to use
1737+
it, as described below.
17281738

17291739
HTTP Client and Responses
17301740
~~~~~~~~~~~~~~~~~~~~~~~~~
17311741

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::
1742+
The first way of using :class:`Symfony\\Component\\HttpClient\\MockHttpClient`
1743+
is to pass a list of responses to its constructor. These will be yielded
1744+
in order when requests are made::
17341745

17351746
use Symfony\Component\HttpClient\MockHttpClient;
17361747
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1745,8 +1756,8 @@ constructor. These will be yielded in order when requests are made::
17451756
$response1 = $client->request('...'); // returns $responses[0]
17461757
$response2 = $client->request('...'); // returns $responses[1]
17471758

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

17511762
use Symfony\Component\HttpClient\MockHttpClient;
17521763
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -1761,7 +1772,9 @@ responses dynamically when it's called::
17611772
.. tip::
17621773

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

17661779
$responses = [
17671780
new MockResponse($body1, $info1),
@@ -1773,7 +1786,8 @@ responses dynamically when it's called::
17731786

17741787
.. versionadded:: 5.4
17751788

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

17781792
If you need to test responses with HTTP status codes different than 200,
17791793
define the ``http_code`` option::
@@ -1789,10 +1803,12 @@ define the ``http_code`` option::
17891803
$response = $client->request('...');
17901804

17911805
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)``).
1806+
:class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`. Any class
1807+
implementing :class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`
1808+
will work (e.g. ``$this->createMock(ResponseInterface::class)``).
17941809

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

17971813
$body = function () {
17981814
yield 'hello';
@@ -1884,7 +1900,8 @@ Then configure Symfony to use your callback:
18841900
Testing Request Data
18851901
~~~~~~~~~~~~~~~~~~~~
18861902

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

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

18941911
.. versionadded:: 5.2
18951912

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

18991917
Usage example::
19001918

0 commit comments

Comments
 (0)