mirror of
https://github.com/symfony/symfony-docs.git
synced 2026-03-24 00:32:14 +01:00
@@ -359,7 +359,7 @@ or by using the second argument of the constructor::
|
||||
|
||||
class ExpressionLanguage extends BaseExpressionLanguage
|
||||
{
|
||||
public function __construct(CacheItemPoolInterface $cache = null, array $providers = [])
|
||||
public function __construct(?CacheItemPoolInterface $cache = null, array $providers = [])
|
||||
{
|
||||
// prepends the default provider to let users override it
|
||||
array_unshift($providers, new StringExpressionLanguageProvider());
|
||||
|
||||
@@ -118,7 +118,7 @@ exists in your project::
|
||||
$this->sportsperson = $sportsperson;
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTime $createdAt = null): void
|
||||
public function setCreatedAt(?\DateTime $createdAt = null): void
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
}
|
||||
@@ -798,7 +798,7 @@ When serializing, you can set a callback to format a specific object property::
|
||||
$encoder = new JsonEncoder();
|
||||
|
||||
// all callback parameters are optional (you can omit the ones you don't use)
|
||||
$dateCallback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
|
||||
$dateCallback = function ($innerObject, $outerObject, string $attributeName, ?string $format = null, array $context = []) {
|
||||
return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
|
||||
};
|
||||
|
||||
@@ -1605,7 +1605,7 @@ having unique identifiers::
|
||||
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
|
||||
|
||||
// all callback parameters are optional (you can omit the ones you don't use)
|
||||
$maxDepthHandler = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
|
||||
$maxDepthHandler = function ($innerObject, $outerObject, string $attributeName, ?string $format = null, array $context = []) {
|
||||
return '/foos/'.$innerObject->id;
|
||||
};
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input::
|
||||
|
||||
class MyCustomProblemNormalizer implements NormalizerInterface
|
||||
{
|
||||
public function normalize($exception, string $format = null, array $context = [])
|
||||
public function normalize($exception, ?string $format = null, array $context = [])
|
||||
{
|
||||
return [
|
||||
'content' => 'This is my custom problem normalizer.',
|
||||
@@ -227,7 +227,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input::
|
||||
];
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
public function supportsNormalization($data, ?string $format = null)
|
||||
{
|
||||
return $data instanceof FlattenException;
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ The type would now look like::
|
||||
])
|
||||
;
|
||||
|
||||
$formModifier = function (FormInterface $form, Sport $sport = null) {
|
||||
$formModifier = function (FormInterface $form, ?Sport $sport = null) {
|
||||
$positions = null === $sport ? [] : $sport->getAvailablePositions();
|
||||
|
||||
$form->add('position', EntityType::class, [
|
||||
|
||||
@@ -68,7 +68,7 @@ version string::
|
||||
* @param string $manifestPath
|
||||
* @param string|null $format
|
||||
*/
|
||||
public function __construct(string $manifestPath, string $format = null)
|
||||
public function __construct(string $manifestPath, ?string $format = null)
|
||||
{
|
||||
$this->manifestPath = $manifestPath;
|
||||
$this->format = $format ?: '%s?%s';
|
||||
|
||||
@@ -1651,7 +1651,7 @@ If you want to extend the behavior of a base HTTP client, you can use
|
||||
{
|
||||
private $decoratedClient;
|
||||
|
||||
public function __construct(HttpClientInterface $decoratedClient = null)
|
||||
public function __construct(?HttpClientInterface $decoratedClient = null)
|
||||
{
|
||||
$this->decoratedClient = $decoratedClient ?? HttpClient::create();
|
||||
}
|
||||
@@ -1667,7 +1667,7 @@ If you want to extend the behavior of a base HTTP client, you can use
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function stream($responses, float $timeout = null): ResponseStreamInterface
|
||||
public function stream($responses, ?float $timeout = null): ResponseStreamInterface
|
||||
{
|
||||
return $this->decoratedClient->stream($responses, $timeout);
|
||||
}
|
||||
|
||||
@@ -2220,7 +2220,7 @@ provided in order to ease the declaration of these special handlers::
|
||||
{
|
||||
use BatchHandlerTrait;
|
||||
|
||||
public function __invoke(MyMessage $message, Acknowledger $ack = null)
|
||||
public function __invoke(MyMessage $message, ?Acknowledger $ack = null)
|
||||
{
|
||||
return $this->handle($message, $ack);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ Here is a simplified example of a database transport::
|
||||
/**
|
||||
* @param FakeDatabase $db is used for demo purposes. It is not a real class.
|
||||
*/
|
||||
public function __construct(FakeDatabase $db, SerializerInterface $serializer = null)
|
||||
public function __construct(FakeDatabase $db, ?SerializerInterface $serializer = null)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->serializer = $serializer ?? new PhpSerializer();
|
||||
|
||||
@@ -778,7 +778,7 @@ and its ``asChatMessage()`` method::
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
|
||||
public function asChatMessage(RecipientInterface $recipient, ?string $transport = null): ?ChatMessage
|
||||
{
|
||||
// Add a custom subject and emoji if the message is sent to Slack
|
||||
if ('slack' === $transport) {
|
||||
|
||||
@@ -255,7 +255,7 @@ request::
|
||||
|
||||
class RequestCollector extends AbstractDataCollector
|
||||
{
|
||||
public function collect(Request $request, Response $response, \Throwable $exception = null)
|
||||
public function collect(Request $request, Response $response, ?\Throwable $exception = null)
|
||||
{
|
||||
$this->data = [
|
||||
'method' => $request->getMethod(),
|
||||
|
||||
@@ -40,7 +40,7 @@ type. The ``Author`` class might look as follows::
|
||||
{
|
||||
protected $bioFile;
|
||||
|
||||
public function setBioFile(File $file = null)
|
||||
public function setBioFile(?File $file = null)
|
||||
{
|
||||
$this->bioFile = $file;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ would be a ``file`` type. The ``Author`` class might look as follows::
|
||||
{
|
||||
protected $headshot;
|
||||
|
||||
public function setHeadshot(File $file = null)
|
||||
public function setHeadshot(?File $file = null)
|
||||
{
|
||||
$this->headshot = $file;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ the value is removed from the collection. For example::
|
||||
|
||||
$builder->add('users', CollectionType::class, [
|
||||
// ...
|
||||
'delete_empty' => function (User $user = null) {
|
||||
'delete_empty' => function (?User $user = null) {
|
||||
return null === $user || empty($user->getFirstName());
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -240,7 +240,7 @@ you do. The resource name itself is not actually used in the example::
|
||||
{
|
||||
private $isLoaded = false;
|
||||
|
||||
public function load($resource, string $type = null)
|
||||
public function load($resource, ?string $type = null)
|
||||
{
|
||||
if (true === $this->isLoaded) {
|
||||
throw new \RuntimeException('Do not add the "extra" loader twice');
|
||||
@@ -267,7 +267,7 @@ you do. The resource name itself is not actually used in the example::
|
||||
return $routes;
|
||||
}
|
||||
|
||||
public function supports($resource, string $type = null)
|
||||
public function supports($resource, ?string $type = null)
|
||||
{
|
||||
return 'extra' === $type;
|
||||
}
|
||||
@@ -412,7 +412,7 @@ configuration file - you can call the
|
||||
|
||||
class AdvancedLoader extends Loader
|
||||
{
|
||||
public function load($resource, string $type = null)
|
||||
public function load($resource, ?string $type = null)
|
||||
{
|
||||
$routes = new RouteCollection();
|
||||
|
||||
@@ -426,7 +426,7 @@ configuration file - you can call the
|
||||
return $routes;
|
||||
}
|
||||
|
||||
public function supports($resource, string $type = null)
|
||||
public function supports($resource, ?string $type = null)
|
||||
{
|
||||
return 'advanced_extra' === $type;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ unauthenticated user tries to access a protected resource::
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function start(Request $request, AuthenticationException $authException = null): RedirectResponse
|
||||
public function start(Request $request, ?AuthenticationException $authException = null): RedirectResponse
|
||||
{
|
||||
// add a custom flash message and redirect to the login page
|
||||
$request->getSession()->getFlashBag()->add('note', 'You have to login in order to access this page.');
|
||||
|
||||
@@ -312,7 +312,7 @@ This will send an email like this to the user:
|
||||
|
||||
class CustomLoginLinkNotification extends LoginLinkNotification
|
||||
{
|
||||
public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage
|
||||
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): ?EmailMessage
|
||||
{
|
||||
$emailMessage = parent::asEmailMessage($recipient, $transport);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``:
|
||||
$this->normalizer = $normalizer;
|
||||
}
|
||||
|
||||
public function normalize($topic, string $format = null, array $context = [])
|
||||
public function normalize($topic, ?string $format = null, array $context = [])
|
||||
{
|
||||
$data = $this->normalizer->normalize($topic, $format, $context);
|
||||
|
||||
@@ -45,7 +45,7 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``:
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, string $format = null, array $context = [])
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = [])
|
||||
{
|
||||
return $data instanceof Topic;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen
|
||||
public $mode = 'strict';
|
||||
|
||||
// all configurable options must be passed to the constructor
|
||||
public function __construct(string $mode = null, string $message = null, array $groups = null, $payload = null)
|
||||
public function __construct(?string $mode = null, ?string $message = null, ?array $groups = null, $payload = null)
|
||||
{
|
||||
parent::__construct([], $groups, $payload);
|
||||
|
||||
@@ -270,9 +270,9 @@ define those options as public properties on the constraint class:
|
||||
|
||||
public function __construct(
|
||||
$mandatoryFooOption,
|
||||
string $message = null,
|
||||
bool $optionalBarOption = null,
|
||||
array $groups = null,
|
||||
?string $message = null,
|
||||
?bool $optionalBarOption = null,
|
||||
?array $groups = null,
|
||||
$payload = null,
|
||||
array $options = []
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user