Skip to content

Commit 3feae69

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: Update phpunit_bridge.rst HTTP client is enabled by default when installed
2 parents 08a54a6 + 71e7144 commit 3feae69

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

components/phpunit_bridge.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,16 +413,16 @@ call to the ``doSetUp()``, ``doTearDown()``, ``doSetUpBeforeClass()`` and
413413

414414
class MyTest extends TestCase
415415
{
416-
// when using the SetUpTearDownTrait, methods like doSetup() can
416+
// when using the SetUpTearDownTrait, methods like doSetUp() can
417417
// be defined with and without the 'void' return type, as you wish
418418
use SetUpTearDownTrait;
419419

420-
private function doSetup()
420+
private function doSetUp()
421421
{
422422
// ...
423423
}
424424

425-
protected function doSetup(): void
425+
protected function doSetUp(): void
426426
{
427427
// ...
428428
}

http_client.rst

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ supports synchronous and asynchronous operations. You can install it with:
1919
Basic Usage
2020
-----------
2121

22-
Use the :class:`Symfony\\Component\\HttpClient\\HttpClient` class to create the
23-
low-level HTTP client that makes requests, like the following ``GET`` request:
22+
Use the :class:`Symfony\\Component\\HttpClient\\HttpClient` class to make
23+
requests. In the Symfony framework, this class is available as the
24+
``http_client`` service. This service will be :doc:`autowired </service_container/autowiring>`
25+
automatically when type-hinting for :class:`Symfony\\Component\\HttpClient\\HttpClientInterface`:
2426

2527
.. configuration-block::
2628

@@ -73,38 +75,11 @@ low-level HTTP client that makes requests, like the following ``GET`` request:
7375
$content = $response->toArray();
7476
// $content = ['id' => 521583, 'name' => 'symfony-docs', ...]
7577
76-
In the Symfony framework, you have to enable the HTTP client integration in
77-
order for the ``HttpClientInterface`` to be :doc:`autowired </service_container/autowiring>`
78-
automatically:
79-
80-
.. configuration-block::
81-
82-
.. code-block:: yaml
83-
84-
# config/packages/framework.yaml
85-
framework:
86-
http_client: true
87-
88-
.. code-block:: xml
89-
90-
<!-- config/packages/framework.xml -->
91-
<?xml version="1.0" encoding="UTF-8" ?>
92-
<container xmlns="http://symfony.com/schema/dic/services"
93-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
94-
xmlns:framework="http://symfony.com/schema/dic/symfony"
95-
xsi:schemaLocation="http://symfony.com/schema/dic/services
96-
https://symfony.com/schema/dic/services/services-1.0.xsd
97-
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
78+
.. tip::
9879

99-
<framework:config http-client="true"/>
100-
</container>
101-
102-
.. code-block:: php
103-
104-
// config/packages/framework.php
105-
$container->loadFromExtension('framework', [
106-
'http_client' => true,
107-
]);
80+
The HTTP client is interopable with many common HTTP client abstractions in
81+
PHP. You can also use any of these abstractions to profit from autowirings.
82+
See `Interoperability`_ for more information.
10883

10984
Configuration
11085
-------------
@@ -1186,17 +1161,42 @@ To use it, you need the ``psr/http-client`` package and a `PSR-17`_ implementati
11861161
# any already installed implementations from common vendors:
11871162
# composer require php-http/discovery
11881163
1189-
Now you can make HTTP requests with the PSR-18 client as follows::
1164+
Now you can make HTTP requests with the PSR-18 client as follows:
1165+
1166+
.. configuration-block::
1167+
1168+
.. code-block:: php-symfony
1169+
1170+
use Psr\Http\Client\ClientInterface;
1171+
1172+
class Symfony
1173+
{
1174+
private $client;
1175+
1176+
public function __construct(ClientInterface $client)
1177+
{
1178+
$this->client = $client;
1179+
}
1180+
1181+
public function getAvailableVersions(): array
1182+
{
1183+
$request = $this->client->createRequest('GET', 'https://symfony.com/versions.json');
1184+
$response = $this->client->sendRequest($request);
1185+
1186+
return json_decode($response->getBody()->getContents(), true);
1187+
}
1188+
}
1189+
1190+
.. code-block:: php-standalone
11901191
1191-
use Symfony\Component\HttpClient\Psr18Client;
1192+
use Symfony\Component\HttpClient\Psr18Client;
11921193
1193-
$client = new Psr18Client();
1194+
$client = new Psr18Client();
11941195
1195-
$url = 'https://symfony.com/versions.json';
1196-
$request = $client->createRequest('GET', $url);
1197-
$response = $client->sendRequest($request);
1196+
$request = $client->createRequest('GET', 'https://symfony.com/versions.json');
1197+
$response = $client->sendRequest($request);
11981198
1199-
$content = json_decode($response->getBody()->getContents(), true);
1199+
$content = json_decode($response->getBody()->getContents(), true);
12001200
12011201
HTTPlug
12021202
~~~~~~~

0 commit comments

Comments
 (0)