Skip to content

Commit d0f8f2b

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: minor [CS] Fix more nullable types [Testing] Update nullable types Reword Refactor Request object documentation and redefine method logic
2 parents b69a44d + 8d91db9 commit d0f8f2b

19 files changed

+59
-40
lines changed

components/expression_language.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ or by using the second argument of the constructor::
385385

386386
class ExpressionLanguage extends BaseExpressionLanguage
387387
{
388-
public function __construct(CacheItemPoolInterface $cache = null, array $providers = [])
388+
public function __construct(?CacheItemPoolInterface $cache = null, array $providers = [])
389389
{
390390
// prepends the default provider to let users override it
391391
array_unshift($providers, new StringExpressionLanguageProvider());

components/serializer.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ exists in your project::
118118
$this->sportsperson = $sportsperson;
119119
}
120120

121-
public function setCreatedAt(\DateTimeInterface $createdAt = null): void
121+
public function setCreatedAt(?\DateTimeInterface $createdAt = null): void
122122
{
123123
$this->createdAt = $createdAt;
124124
}
@@ -723,7 +723,7 @@ When serializing, you can set a callback to format a specific object property::
723723
$encoder = new JsonEncoder();
724724

725725
// all callback parameters are optional (you can omit the ones you don't use)
726-
$dateCallback = function (object $innerObject, object $outerObject, string $attributeName, string $format = null, array $context = []): string {
726+
$dateCallback = function (object $innerObject, object $outerObject, string $attributeName, ?string $format = null, array $context = []): string {
727727
return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
728728
};
729729

@@ -1574,7 +1574,7 @@ having unique identifiers::
15741574
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
15751575

15761576
// all callback parameters are optional (you can omit the ones you don't use)
1577-
$maxDepthHandler = function (object $innerObject, object $outerObject, string $attributeName, string $format = null, array $context = []): string {
1577+
$maxDepthHandler = function (object $innerObject, object $outerObject, string $attributeName, ?string $format = null, array $context = []): string {
15781578
return '/foos/'.$innerObject->id;
15791579
};
15801580

controller/error_pages.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input::
216216

217217
class MyCustomProblemNormalizer implements NormalizerInterface
218218
{
219-
public function normalize($exception, string $format = null, array $context = []): array
219+
public function normalize($exception, ?string $format = null, array $context = []): array
220220
{
221221
return [
222222
'content' => 'This is my custom problem normalizer.',
@@ -227,7 +227,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input::
227227
];
228228
}
229229

230-
public function supportsNormalization($data, string $format = null, array $context = []): bool
230+
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
231231
{
232232
return $data instanceof FlattenException;
233233
}

form/dynamic_form_modification.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ The type would now look like::
455455
])
456456
;
457457

458-
$formModifier = function (FormInterface $form, Sport $sport = null): void {
458+
$formModifier = function (FormInterface $form, ?Sport $sport = null): void {
459459
$positions = null === $sport ? [] : $sport->getAvailablePositions();
460460

461461
$form->add('position', EntityType::class, [
@@ -487,7 +487,7 @@ The type would now look like::
487487
$formModifier($event->getForm()->getParent(), $sport);
488488
}
489489
);
490-
490+
491491
// by default, action does not appear in the <form> tag
492492
// you can set this value by passing the controller route
493493
$builder->setAction($options['action']);

http_client.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ If you want to extend the behavior of a base HTTP client, you can use
17721772
class MyExtendedHttpClient implements HttpClientInterface
17731773
{
17741774
public function __construct(
1775-
private HttpClientInterface $decoratedClient = null
1775+
private ?HttpClientInterface $decoratedClient = null
17761776
) {
17771777
$this->decoratedClient ??= HttpClient::create();
17781778
}
@@ -1788,7 +1788,7 @@ If you want to extend the behavior of a base HTTP client, you can use
17881788
return $response;
17891789
}
17901790

1791-
public function stream($responses, float $timeout = null): ResponseStreamInterface
1791+
public function stream($responses, ?float $timeout = null): ResponseStreamInterface
17921792
{
17931793
return $this->decoratedClient->stream($responses, $timeout);
17941794
}

messenger.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,7 @@ provided in order to ease the declaration of these special handlers::
25382538
{
25392539
use BatchHandlerTrait;
25402540

2541-
public function __invoke(MyMessage $message, Acknowledger $ack = null): mixed
2541+
public function __invoke(MyMessage $message, ?Acknowledger $ack = null): mixed
25422542
{
25432543
return $this->handle($message, $ack);
25442544
}

messenger/custom-transport.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Here is a simplified example of a database transport::
5151
*/
5252
public function __construct(
5353
private FakeDatabase $db,
54-
SerializerInterface $serializer = null,
54+
?SerializerInterface $serializer = null,
5555
) {
5656
$this->serializer = $serializer ?? new PhpSerializer();
5757
}

notifier.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ and its ``asChatMessage()`` method::
770770
) {
771771
}
772772

773-
public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
773+
public function asChatMessage(RecipientInterface $recipient, ?string $transport = null): ?ChatMessage
774774
{
775775
// Add a custom subject and emoji if the message is sent to Slack
776776
if ('slack' === $transport) {

profiler.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ request::
281281

282282
class RequestCollector extends AbstractDataCollector
283283
{
284-
public function collect(Request $request, Response $response, \Throwable $exception = null): void
284+
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
285285
{
286286
$this->data = [
287287
'method' => $request->getMethod(),

reference/constraints/File.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type. The ``Author`` class might look as follows::
4040
{
4141
protected File $bioFile;
4242

43-
public function setBioFile(File $file = null): void
43+
public function setBioFile(?File $file = null): void
4444
{
4545
$this->bioFile = $file;
4646
}

reference/constraints/Image.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ would be a ``file`` type. The ``Author`` class might look as follows::
3535
{
3636
protected File $headshot;
3737

38-
public function setHeadshot(File $file = null): void
38+
public function setHeadshot(?File $file = null): void
3939
{
4040
$this->headshot = $file;
4141
}

reference/forms/types/collection.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ the value is removed from the collection. For example::
160160

161161
$builder->add('users', CollectionType::class, [
162162
// ...
163-
'delete_empty' => function (User $user = null): bool {
163+
'delete_empty' => function (?User $user = null): bool {
164164
return null === $user || empty($user->getFirstName());
165165
},
166166
]);

routing/custom_route_loader.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ you do. The resource name itself is not actually used in the example::
271271
{
272272
private bool $isLoaded = false;
273273

274-
public function load($resource, string $type = null): RouteCollection
274+
public function load($resource, ?string $type = null): RouteCollection
275275
{
276276
if (true === $this->isLoaded) {
277277
throw new \RuntimeException('Do not add the "extra" loader twice');
@@ -298,7 +298,7 @@ you do. The resource name itself is not actually used in the example::
298298
return $routes;
299299
}
300300

301-
public function supports($resource, string $type = null): bool
301+
public function supports($resource, ?string $type = null): bool
302302
{
303303
return 'extra' === $type;
304304
}
@@ -443,7 +443,7 @@ configuration file - you can call the
443443

444444
class AdvancedLoader extends Loader
445445
{
446-
public function load($resource, string $type = null): RouteCollection
446+
public function load($resource, ?string $type = null): RouteCollection
447447
{
448448
$routes = new RouteCollection();
449449

@@ -457,7 +457,7 @@ configuration file - you can call the
457457
return $routes;
458458
}
459459

460-
public function supports($resource, string $type = null): bool
460+
public function supports($resource, ?string $type = null): bool
461461
{
462462
return 'advanced_extra' === $type;
463463
}

security/access_denied_handler.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ unauthenticated user tries to access a protected resource::
3838
) {
3939
}
4040

41-
public function start(Request $request, AuthenticationException $authException = null): RedirectResponse
41+
public function start(Request $request, ?AuthenticationException $authException = null): RedirectResponse
4242
{
4343
// add a custom flash message and redirect to the login page
4444
$request->getSession()->getFlashBag()->add('note', 'You have to login in order to access this page.');

security/login_link.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ This will send an email like this to the user:
283283

284284
class CustomLoginLinkNotification extends LoginLinkNotification
285285
{
286-
public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage
286+
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): ?EmailMessage
287287
{
288288
$emailMessage = parent::asEmailMessage($recipient, $transport);
289289

serializer/custom_normalizer.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ normalization process::
3535
) {
3636
}
3737

38-
public function normalize($topic, string $format = null, array $context = []): array
38+
public function normalize($topic, ?string $format = null, array $context = []): array
3939
{
4040
$data = $this->normalizer->normalize($topic, $format, $context);
4141

@@ -47,7 +47,7 @@ normalization process::
4747
return $data;
4848
}
4949

50-
public function supportsNormalization($data, string $format = null, array $context = []): bool
50+
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
5151
{
5252
return $data instanceof Topic;
5353
}

testing.rst

+11-11
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,13 @@ returns a ``Crawler`` instance.
555555

556556
The full signature of the ``request()`` method is::
557557

558-
request(
558+
public function request(
559559
string $method,
560560
string $uri,
561561
array $parameters = [],
562562
array $files = [],
563563
array $server = [],
564-
string $content = null,
564+
?string $content = null,
565565
bool $changeHistory = true
566566
): Crawler
567567

@@ -960,7 +960,7 @@ Response Assertions
960960
Asserts that the response was successful (HTTP status is 2xx).
961961
``assertResponseStatusCodeSame(int $expectedCode, string $message = '')``
962962
Asserts a specific HTTP status code.
963-
``assertResponseRedirects(string $expectedLocation = null, int $expectedCode = null, string $message = '')``
963+
``assertResponseRedirects(?string $expectedLocation = null, ?int $expectedCode = null, string $message = '')``
964964
Asserts the response is a redirect response (optionally, you can check
965965
the target location and status code). The excepted location can be either
966966
an absolute or a relative path.
@@ -969,10 +969,10 @@ Response Assertions
969969
``assertResponseHeaderSame(string $headerName, string $expectedValue, string $message = '')``/``assertResponseHeaderNotSame(string $headerName, string $expectedValue, string $message = '')``
970970
Asserts the given header does (not) contain the expected value on the
971971
response, e.g. ``assertResponseHeaderSame('content-type', 'application/octet-stream');``.
972-
``assertResponseHasCookie(string $name, string $path = '/', string $domain = null, string $message = '')``/``assertResponseNotHasCookie(string $name, string $path = '/', string $domain = null, string $message = '')``
972+
``assertResponseHasCookie(string $name, string $path = '/', ?string $domain = null, string $message = '')``/``assertResponseNotHasCookie(string $name, string $path = '/', ?string $domain = null, string $message = '')``
973973
Asserts the given cookie is present in the response (optionally
974974
checking for a specific cookie path or domain).
975-
``assertResponseCookieValueSame(string $name, string $expectedValue, string $path = '/', string $domain = null, string $message = '')``
975+
``assertResponseCookieValueSame(string $name, string $expectedValue, string $path = '/', ?string $domain = null, string $message = '')``
976976
Asserts the given cookie is present and set to the expected value.
977977
``assertResponseFormatSame(?string $expectedFormat, string $message = '')``
978978
Asserts the response format returned by the
@@ -993,10 +993,10 @@ Request Assertions
993993
Browser Assertions
994994
..................
995995

996-
``assertBrowserHasCookie(string $name, string $path = '/', string $domain = null, string $message = '')``/``assertBrowserNotHasCookie(string $name, string $path = '/', string $domain = null, string $message = '')``
996+
``assertBrowserHasCookie(string $name, string $path = '/', ?string $domain = null, string $message = '')``/``assertBrowserNotHasCookie(string $name, string $path = '/', ?string $domain = null, string $message = '')``
997997
Asserts that the test Client does (not) have the given cookie set
998998
(meaning, the cookie was set by any response in the test).
999-
``assertBrowserCookieValueSame(string $name, string $expectedValue, string $path = '/', string $domain = null, string $message = '')``
999+
``assertBrowserCookieValueSame(string $name, string $expectedValue, string $path = '/', ?string $domain = null, string $message = '')``
10001000
Asserts the given cookie in the test Client is set to the expected
10011001
value.
10021002
``assertThatForClient(Constraint $constraint, string $message = '')``
@@ -1047,18 +1047,18 @@ Crawler Assertions
10471047
Mailer Assertions
10481048
.................
10491049

1050-
``assertEmailCount(int $count, string $transport = null, string $message = '')``
1050+
``assertEmailCount(int $count, ?string $transport = null, string $message = '')``
10511051
Asserts that the expected number of emails was sent.
1052-
``assertQueuedEmailCount(int $count, string $transport = null, string $message = '')``
1052+
``assertQueuedEmailCount(int $count, ?string $transport = null, string $message = '')``
10531053
Asserts that the expected number of emails was queued (e.g. using the
10541054
Messenger component).
10551055
``assertEmailIsQueued(MessageEvent $event, string $message = '')``/``assertEmailIsNotQueued(MessageEvent $event, string $message = '')``
10561056
Asserts that the given mailer event is (not) queued. Use
1057-
``getMailerEvent(int $index = 0, string $transport = null)`` to
1057+
``getMailerEvent(int $index = 0, ?string $transport = null)`` to
10581058
retrieve a mailer event by index.
10591059
``assertEmailAttachmentCount(RawMessage $email, int $count, string $message = '')``
10601060
Asserts that the given email has the expected number of attachments. Use
1061-
``getMailerMessage(int $index = 0, string $transport = null)`` to
1061+
``getMailerMessage(int $index = 0, ?string $transport = null)`` to
10621062
retrieve a specific email by index.
10631063
``assertEmailTextBodyContains(RawMessage $email, string $text, string $message = '')``/``assertEmailTextBodyNotContains(RawMessage $email, string $text, string $message = '')``
10641064
Asserts that the text body of the given email does (not) contain the

translation.rst

+19
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,25 @@ the framework:
963963
This ``default_locale`` is also relevant for the translator, as shown in the
964964
next section.
965965

966+
Selecting the Language Preferred by the User
967+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
968+
969+
If your application supports multiple languages, the first time a user visits your
970+
site it's common to redirect them to the best possible language according to their
971+
preferences. This is achieved with the ``getPreferredLanguage()`` method of the
972+
:ref:`Request object <controller-request-argument>`::
973+
974+
// get the Request object somehow (e.g. as a controller argument)
975+
$request = ...
976+
// pass an array of the locales (their script and region parts are optional) supported
977+
// by your application and the method returns the best locale for the current user
978+
$locale = $request->getPreferredLanguage(['pt', 'fr_Latn_CH', 'en_US'] );
979+
980+
Symfony finds the best possible language based on the locales passed as argument
981+
and the value of the ``Accept-Language`` HTTP header. If it can't find a perfect
982+
match between them, this method returns the first locale passed as argument
983+
(that's why the order of the passed locales is important).
984+
966985
.. _translation-fallback:
967986

968987
Fallback Translation Locales

validation/custom_constraint.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen
2727
public string $mode = 'strict';
2828
2929
// all configurable options must be passed to the constructor
30-
public function __construct(string $mode = null, string $message = null, array $groups = null, $payload = null)
30+
public function __construct(?string $mode = null, ?string $message = null, ?array $groups = null, $payload = null)
3131
{
3232
parent::__construct([], $groups, $payload);
3333
@@ -243,9 +243,9 @@ define those options as public properties on the constraint class::
243243

244244
public function __construct(
245245
$mandatoryFooOption,
246-
string $message = null,
247-
bool $optionalBarOption = null,
248-
array $groups = null,
246+
?string $message = null,
247+
?bool $optionalBarOption = null,
248+
?array $groups = null,
249249
$payload = null,
250250
array $options = []
251251
) {

0 commit comments

Comments
 (0)