Skip to content

Commit 95494c5

Browse files
committed
Merge branch '4.1'
* 4.1: Added a tip about atPath() method Remove useless use statements Added the missing class imports Update upload_file.rst for handling FileException Fix environment variable name
2 parents 06dbeb5 + 5e9d47e commit 95494c5

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

controller/upload_file.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Finally, you need to update the code of the controller that handles the form::
100100
namespace App\Controller;
101101

102102
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
103+
use Symfony\Component\HttpFoundation\File\Exception\FileException;
103104
use Symfony\Component\HttpFoundation\Request;
104105
use Symfony\Component\Routing\Annotation\Route;
105106
use App\Entity\Product;
@@ -123,11 +124,15 @@ Finally, you need to update the code of the controller that handles the form::
123124

124125
$fileName = $this->generateUniqueFileName().'.'.$file->guessExtension();
125126

126-
// moves the file to the directory where brochures are stored
127-
$file->move(
128-
$this->getParameter('brochures_directory'),
129-
$fileName
130-
);
127+
// Move the file to the directory where brochures are stored
128+
try {
129+
$file->move(
130+
$this->getParameter('brochures_directory'),
131+
$fileName
132+
);
133+
} catch (FileException $e) {
134+
// ... handle exception if something happens during file upload
135+
}
131136

132137
// updates the 'brochure' property to store the PDF file name
133138
// instead of its contents
@@ -219,6 +224,7 @@ logic to a separate service::
219224
// src/Service/FileUploader.php
220225
namespace App\Service;
221226

227+
use Symfony\Component\HttpFoundation\File\Exception\FileException;
222228
use Symfony\Component\HttpFoundation\File\UploadedFile;
223229

224230
class FileUploader
@@ -234,7 +240,11 @@ logic to a separate service::
234240
{
235241
$fileName = md5(uniqid()).'.'.$file->guessExtension();
236242

237-
$file->move($this->getTargetDirectory(), $fileName);
243+
try {
244+
$file->move($this->getTargetDir(), $fileName);
245+
} catch (FileException $e) {
246+
// ... handle exception if something happens during file upload
247+
}
238248

239249
return $fileName;
240250
}

messenger.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ the messenger component, the following configuration should have been created:
159159
160160
# .env
161161
###> symfony/messenger ###
162-
MESSENGER_DSN=amqp://guest:guest@localhost:5672/%2f/messages
162+
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
163163
###< symfony/messenger ###
164164
165165
This is enough to allow you to route your message to the ``amqp`` transport.

reference/forms/types/options/property_path.rst.inc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ property_path
33

44
**type**: ``PropertyPathInterface|string|null`` **default**: ``null``
55

6-
Fields display a property value of the form's domain object by default.
7-
When the form is submitted, the submitted value is written back into the
8-
object.
9-
10-
If you want to override the property that a field reads from and writes
11-
to, you can set the ``property_path`` option. Its default value (``null``)
12-
will use the field's name as the property.
6+
By default (when the value of this option is ``null``) form fields read from and
7+
write to the properties with the same names in the form's domain object. The
8+
``property_path`` option lets you define which property a field reads from and
9+
writes to. The value of this option can be any
10+
:doc:`valid PropertyAccess syntax </components/property_access>`.

security/impersonating_user.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ In some cases you may need to get the object that represents the impersonator
9393
user rather than the impersonated user. Use the following snippet to iterate
9494
over the user's roles until you find one that is a ``SwitchUserRole`` object::
9595

96-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
97-
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
9896
use Symfony\Component\Security\Core\Role\SwitchUserRole;
9997
use Symfony\Component\Security\Core\Security;
10098
// ...

validation/custom_constraint.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ With this, the validator ``validate()`` method gets an object as its first argum
196196
}
197197
}
198198

199+
.. tip::
200+
201+
The ``atPath()`` method defines the property which the validation error is
202+
associated to. Use any :doc:`valid PropertyAccess syntax </components/property_access>`
203+
to define that property.
204+
199205
Note that a class constraint validator is applied to the class itself, and
200206
not to the property:
201207

0 commit comments

Comments
 (0)