Skip to content

Commit cf2d65a

Browse files
committed
Merge remote-tracking branch 'upstream/master'
* upstream/master: Remove old deprecated directive Add missing deprecated directive for kernel.log_dir parameter Correct log dir parameter s/bahavior/behavior Use uppercase in title Fix XML syntax removing notes about doctrine_clear_entity_manager middleware There is no handler file in storage Missing closing parentheses and closing bracket Remove unused imports Add missing semicolon User double \ instead of four \ in expression service [PHPUnit Bridge] Minor tweaks related to polyfills Fix DOCtor-RST build on master Complete doc for 4.4 features Adapted the HTTPlug integration docs to Async Client
2 parents 45c286a + dea2556 commit cf2d65a

File tree

10 files changed

+117
-50
lines changed

10 files changed

+117
-50
lines changed

.doctor-rst.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ whitelist:
8282
- '$var .= "Because of this `\xE9` octet (\\xE9),\n";'
8383
- "`Deploying Symfony 4 Apps on Heroku`_."
8484
- ".. _`Deploying Symfony 4 Apps on Heroku`: https://devcenter.heroku.com/articles/deploying-symfony4"
85+
- "// 224, 165, 141, 224, 164, 164, 224, 165, 135])"

bundles/extension.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ they are compiled when generating the application cache to improve the overall
119119
performance. Define the list of annotated classes to compile in the
120120
``addAnnotatedClassesToCompile()`` method::
121121

122-
use App\Manager\UserManager;
123-
use App\Utils\Slugger;
124-
125-
// ...
126122
public function load(array $configs, ContainerBuilder $container)
127123
{
128124
// ...

components/http_client.rst

Lines changed: 102 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ The HTTP client supports different authentication mechanisms. They can be
124124
defined globally when creating the client (to apply it to all requests) and to
125125
each request (which overrides any global authentication)::
126126

127-
// Use the same authentication for all requests
128-
$client = HttpClient::create([
127+
// Use the same authentication for all requests to https://example.com/
128+
$client = HttpClient::createForBaseUri('https://example.com/', [
129129
// HTTP Basic authentication (there are multiple ways of configuring it)
130130
'auth_basic' => ['the-username'],
131131
'auth_basic' => ['the-username', 'the-password'],
@@ -150,6 +150,8 @@ each request (which overrides any global authentication)::
150150
.. note::
151151

152152
The NTLM authentication mechanism requires using the cURL transport.
153+
By using ``HttpClient::createForBaseUri()``, we ensure that the auth credentials
154+
won't be sent to any other hosts than https://example.com/.
153155

154156
Query String Parameters
155157
~~~~~~~~~~~~~~~~~~~~~~~
@@ -366,10 +368,7 @@ Call the ``stream()`` method of the HTTP client to get *chunks* of the
366368
response sequentially instead of waiting for the entire response::
367369

368370
$url = 'https://releases.ubuntu.com/18.04.1/ubuntu-18.04.1-desktop-amd64.iso';
369-
$response = $client->request('GET', $url, [
370-
// optional: if you don't want to buffer the response in memory
371-
'buffer' => false,
372-
]);
371+
$response = $client->request('GET', $url);
373372

374373
// Responses are lazy: this code is executed as soon as headers are received
375374
if (200 !== $response->getStatusCode()) {
@@ -383,6 +382,14 @@ response sequentially instead of waiting for the entire response::
383382
fwrite($fileHandler, $chunk->getContent());
384383
}
385384

385+
.. note::
386+
387+
By default, ``text/*``, JSON and XML response bodies are buffered in a local
388+
``php://temp`` stream. You can control this behavior by using the ``buffer``
389+
option: set it to ``true``/``false`` to enable/disable buffering, or to a
390+
closure that should return the same based on the response headers it receives
391+
as argument.
392+
386393
Canceling Responses
387394
~~~~~~~~~~~~~~~~~~~
388395

@@ -525,6 +532,8 @@ response and get remaining contents that might come back in a new timeout, etc.
525532
is idle*. Big responses can last as long as needed to complete, provided they
526533
remain active during the transfer and never pause for longer than specified.
527534

535+
Use the ``max_duration`` option to limit the time a full request/response can last.
536+
528537
Dealing with Network Errors
529538
~~~~~~~~~~~~~~~~~~~~~~~~~~~
530539

@@ -650,15 +659,15 @@ or if it matches the ``https://api.github.com/`` base URI.
650659
Interoperability
651660
----------------
652661

653-
The component is interoperable with three different abstractions for HTTP
654-
clients: `Symfony Contracts`_, `PSR-18`_ and `HTTPlug`_ v1 and v2. If your
655-
application uses libraries that need any of them, the component is compatible
662+
The component is interoperable with four different abstractions for HTTP
663+
clients: `Symfony Contracts`_, `PSR-18`_, `HTTPlug`_ v1/v2 and native PHP streams.
664+
If your application uses libraries that need any of them, the component is compatible
656665
with all of them. They also benefit from :ref:`autowiring aliases <service-autowiring-alias>`
657666
when the :ref:`framework bundle <framework-bundle-configuration>` is used.
658667

659668
If you are writing or maintaining a library that makes HTTP requests, you can
660669
decouple it from any specific HTTP client implementations by coding against
661-
either Symfony Contracts (recommended) or PSR-18 (which superseded HTTPlug).
670+
either Symfony Contracts (recommended), PSR-18 or HTTPlug v2.
662671

663672
Symfony Contracts
664673
~~~~~~~~~~~~~~~~~
@@ -676,7 +685,7 @@ interface you need to code against when a client is needed::
676685

677686
public function __construct(HttpClientInterface $client)
678687
{
679-
$this->client = $client
688+
$this->client = $client;
680689
}
681690

682691
// [...]
@@ -685,7 +694,7 @@ interface you need to code against when a client is needed::
685694
All request options mentioned above (e.g. timeout management) are also defined
686695
in the wordings of the interface, so that any compliant implementations (like
687696
this component) is guaranteed to provide them. That's a major difference with
688-
the PSR-18 abstraction, which provides none related to the transport itself.
697+
the other abstractions, which provide none related to the transport itself.
689698

690699
Another major feature covered by the Symfony Contracts is async/multiplexing,
691700
as described in the previous sections.
@@ -710,6 +719,10 @@ To use it, you need the ``psr/http-client`` package and a `PSR-17`_ implementati
710719
# with autowiring aliases provided by Symfony Flex
711720
$ composer require nyholm/psr7
712721
722+
# alternatively, install the php-http/discovery package to auto-discover
723+
# any already installed implementations from common vendors:
724+
# composer require php-http/discovery
725+
713726
Now you can make HTTP requests with the PSR-18 client as follows::
714727

715728
use Symfony\Component\HttpClient\Psr18Client;
@@ -725,27 +738,26 @@ Now you can make HTTP requests with the PSR-18 client as follows::
725738
HTTPlug
726739
~~~~~~~
727740

728-
The `HTTPlug`_ specification was published before PSR-18 and is superseded by
729-
it. As such, you should not use it in newly written code. Yet, many libraries
730-
still require v1 or v2 of it. The component is interoperable with them thanks to
731-
the ``HttplugClient`` adapter class. Similarly to ``Psr18Client`` implementing
732-
relevant parts of PSR-17, ``HttplugClient`` also implements the factory methods
733-
defined in the related ``php-http/message-factory`` package.
734-
735-
Internally, the implementation relies on the ``Psr18Client``, so that the
736-
``psr/http-client`` package is needed to use this class:
741+
The `HTTPlug`_ v1 specification was published before PSR-18 and is superseded by
742+
it. As such, you should not use it in newly written code. The component is still
743+
interoperable with libraries that require it thanks to the
744+
:class:`Symfony\\Component\\HttpClient\\HttplugClient` class. Similarly to
745+
``Psr18Client`` implementing relevant parts of PSR-17, ``HttplugClient`` also
746+
implements the factory methods defined in the related ``php-http/message-factory``
747+
package.
737748

738749
.. code-block:: terminal
739750
740751
# Let's suppose php-http/httplug is already required by the lib you want to use
741752
742-
# installs the PSR-18 ClientInterface
743-
$ composer require psr/http-client
744-
745753
# installs an efficient implementation of response and stream factories
746754
# with autowiring aliases provided by Symfony Flex
747755
$ composer require nyholm/psr7
748756
757+
# alternatively, install the php-http/discovery package to auto-discover
758+
# any already installed implementations from common vendors:
759+
# composer require php-http/discovery
760+
749761
Let's say you want to instantiate a class with the following constructor,
750762
that requires HTTPlug dependencies::
751763

@@ -770,6 +782,72 @@ Because ``HttplugClient`` implements the three interfaces, you can use it this w
770782
$httpClient = new HttplugClient();
771783
$apiClient = new SomeSdk($httpClient, $httpClient, $httpClient);
772784

785+
If you'd like to work with promises, ``HttplugClient`` also implements the
786+
``HttpAsyncClient`` interface. To use it, you need to install the
787+
``guzzlehttp/promises`` package:
788+
789+
.. code-block:: terminal
790+
791+
$ composer require guzzlehttp/promises
792+
793+
Then you're ready to go::
794+
795+
use Psr\Http\Message\ResponseInterface;
796+
use Symfony\Component\HttpClient\HttplugClient;
797+
798+
$httpClient = new HttplugClient();
799+
$request = $httpClient->createRequest('GET', 'https://my.api.com/');
800+
$promise = $httpClient->sendRequest($request)
801+
->then(
802+
function (ResponseInterface $response) {
803+
echo 'Got status '.$response->getStatusCode();
804+
805+
return $response;
806+
},
807+
function (\Throwable $exception) {
808+
echo 'Error: '.$exception->getMessage();
809+
810+
throw $exception;
811+
}
812+
);
813+
814+
// after you're done with sending several requests,
815+
// you must wait for them to complete concurrently
816+
817+
// wait for a specific promise to resolve while monitoring them all
818+
$response = $promise->wait();
819+
820+
// wait maximum 1 second for pending promises to resolve
821+
$httpClient->wait(1.0);
822+
823+
// wait for all remaining promises to resolve
824+
$httpClient->wait();
825+
826+
Native PHP Streams
827+
~~~~~~~~~~~~~~~~~~
828+
829+
Responses implementing :class:`Symfony\\Contracts\\HttpClient\\ResponseInterface`
830+
can be cast to native PHP streams with
831+
:method:`Symfony\\Component\\HttpClient\\Response\\StreamWrapper::createResource``.
832+
This allows using them where native PHP streams are needed::
833+
834+
use Symfony\Component\HttpClient\HttpClient;
835+
use Symfony\Component\HttpClient\Response\StreamWrapper;
836+
837+
$client = HttpClient::create();
838+
$response = $client->request('GET', 'https://symfony.com/versions.json');
839+
840+
$streamResource = StreamWrapper::createResource($response, $client);
841+
842+
// alternatively and contrary to the previous one, this returns
843+
// a resource that is seekable and potentially stream_select()-able
844+
$streamResource = $response->toStream();
845+
846+
echo stream_get_contents($streamResource); // outputs the content of the response
847+
848+
// later on if you need to, you can access the response from the stream
849+
$response = stream_get_meta_data($streamResource)['wrapper_data']->getResponse();
850+
773851
Symfony Framework Integration
774852
-----------------------------
775853

components/messenger.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ do is to write your own CSV receiver::
296296
throw $exception;
297297
}
298298

299-
return [$envelope->with(new CustomStamp($yourEnvelope['id']);
299+
return [$envelope->with(new CustomStamp($yourEnvelope['id']))];
300300
}
301301

302302
public function ack(Envelope $envelope): void

components/phpunit_bridge.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ Polyfills for the Unavailable Methods
389389

390390
When using the ``simple-phpunit`` script, PHPUnit Bridge injects polyfills for
391391
most methods of the ``TestCase`` and ``Assert`` classes (e.g. ``expectException()``,
392-
``expectExcpetionMessage()``, ``assertContainsEquals``, etc.). This allows writing
392+
``expectExceptionMessage()``, ``assertContainsEquals()``, etc.). This allows writing
393393
test cases using the latest best practices while still remaining compatible with
394394
older PHPUnit versions.
395395

@@ -413,18 +413,18 @@ call to the ``doSetUp()``, ``doTearDown()``, ``doSetUpBeforeClass()`` and
413413

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

418-
private $state;
419-
420420
private function doSetup()
421421
{
422-
$this->state = 'demo';
422+
// ...
423423
}
424424

425425
protected function doSetup(): void
426426
{
427-
// visibility and return type-hint of method is free
427+
// ...
428428
}
429429
}
430430

@@ -686,7 +686,7 @@ toggle a behavior::
686686
public function hello(): string
687687
{
688688
if (class_exists(DependencyClass::class)) {
689-
return 'The dependency bahavior.';
689+
return 'The dependency behavior.';
690690
}
691691

692692
return 'The default behavior.';
@@ -704,7 +704,7 @@ are installed during tests) would look like::
704704
public function testHello()
705705
{
706706
$class = new MyClass();
707-
$result = $class->hello(); // "The dependency bahavior."
707+
$result = $class->hello(); // "The dependency behavior."
708708

709709
// ...
710710
}
@@ -728,7 +728,7 @@ classes, interfaces and/or traits for the code to run::
728728
ClassExistsMock::withMockedClasses([DependencyClass::class => false]);
729729

730730
$class = new MyClass();
731-
$result = $class->hello(); // "The default bahavior."
731+
$result = $class->hello(); // "The default behavior."
732732

733733
// ...
734734
}

doctrine/pdo_session_storage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Preparing the Database to Store Sessions
184184

185185
Before storing sessions in the database, you must create the table that stores
186186
the information. The session handler provides a method called
187-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler::createTable`
187+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler::createTable`
188188
to set up this table for you according to the database engine used::
189189

190190
try {

messenger.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,11 +1379,6 @@ may want to use:
13791379
# or pass a different entity manager to any
13801380
#- doctrine_transaction: ['custom']
13811381
1382-
# After handling, the clear() method is executed in the
1383-
# entity manager, which reduces the memory consumption and
1384-
# avoids side-effects related to unrefreshed entities
1385-
- doctrine_clear_entity_manager
1386-
13871382
.. code-block:: xml
13881383
13891384
<!-- config/packages/messenger.xml -->
@@ -1409,8 +1404,6 @@ may want to use:
14091404
<framework:argument>custom</framework:argument>
14101405
</framework:middleware>
14111406
-->
1412-
1413-
<framework:middleware id="doctrine_clear_entity_manager"/>
14141407
</framework:bus>
14151408
</framework:messenger>
14161409
</framework:config>
@@ -1429,7 +1422,6 @@ may want to use:
14291422
'doctrine_close_connection',
14301423
// Using another entity manager
14311424
['id' => 'doctrine_transaction', 'arguments' => ['custom']],
1432-
'doctrine_clear_entity_manager',
14331425
],
14341426
],
14351427
],

reference/configuration/kernel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ This returns the absolute path of the log directory of your Symfony project.
107107
It's calculated automatically based on the current
108108
:ref:`environment <configuration-environments>`.
109109

110-
This value is exposed via the ``kernel.log_dir`` configuration parameter and
110+
This value is exposed via the ``kernel.logs_dir`` configuration parameter and
111111
the :method:`Symfony\\Component\\HttpKernel\\Kernel::getLogDir` method. To
112112
change this setting, override the ``getLogDir()`` method to return the right
113113
log directory.

routing.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ defined as ``/blog/{slug}``:
431431
432432
<route id="blog_show" path="/blog/{slug}"
433433
controller="App\Controller\BlogController::show"/>
434-
</route>
435434
</routes>
436435
437436
.. code-block:: php
@@ -525,7 +524,6 @@ the ``{page}`` parameter using the ``requirements`` option:
525524
526525
<route id="blog_show" path="/blog/{slug}"
527526
controller="App\Controller\BlogController::show"/>
528-
</route>
529527
</routes>
530528
531529
.. code-block:: php

service_container/expression_language.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ to another service: ``App\Mailer``. One way to do this is with an expression:
2828
App\Mail\MailerConfiguration: ~
2929
3030
App\Mailer:
31-
arguments: ["@=service('App\\\\Mail\\\\MailerConfiguration').getMailerMethod()"]
31+
arguments: ['@=service("App\\Mail\\MailerConfiguration").getMailerMethod()']
32+
# when using double-quoted strings, the backslash needs to be escaped twice (see https://yaml.org/spec/1.2/spec.html#id2787109)
33+
# arguments: ["@=service('App\\\\Mail\\\\MailerConfiguration').getMailerMethod()"]
3234
3335
.. code-block:: xml
3436

0 commit comments

Comments
 (0)