File tree 10 files changed +42
-43
lines changed
Filter options
10 files changed +42
-43
lines changed
Original file line number Diff line number Diff line change @@ -238,12 +238,20 @@ more advanced use-case, you can always do the same security check in PHP:
238
238
// equivalent code without using the "denyAccessUnlessGranted()" shortcut:
239
239
//
240
240
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
241
+ // use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
242
+ //
243
+ // ...
244
+ //
245
+ // public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
246
+ // $this->authorizationChecker = $authorizationChecker;
247
+ // }
248
+ //
241
249
// ...
242
250
//
243
- // if (!$this->get('security.authorization_checker') ->isGranted('edit', $post)) {
251
+ // if (!$this->authorizationChecker ->isGranted('edit', $post)) {
244
252
// throw $this->createAccessDeniedException();
245
253
// }
246
-
254
+ //
247
255
// ...
248
256
}
249
257
@@ -357,14 +365,22 @@ via the even easier shortcut in a controller:
357
365
358
366
$this->denyAccessUnlessGranted('edit', $post);
359
367
360
- // or without the shortcut:
361
- //
362
368
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
369
+ // use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
370
+ //
363
371
// ...
364
372
//
365
- // if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
373
+ // public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
374
+ // $this->authorizationChecker = $authorizationChecker;
375
+ // }
376
+ //
377
+ // ...
378
+ //
379
+ // if (!$this->authorizationChecker->isGranted('edit', $post)) {
366
380
// throw $this->createAccessDeniedException();
367
381
// }
382
+ //
383
+ // ...
368
384
}
369
385
370
386
Learn More
Original file line number Diff line number Diff line change @@ -459,8 +459,9 @@ CamelCase to snake_case
459
459
~~~~~~~~~~~~~~~~~~~~~~~
460
460
461
461
In many formats, it's common to use underscores to separate words (also known
462
- as snake_case). However, PSR-1 specifies that the preferred style for PHP
463
- properties and methods is CamelCase.
462
+ as snake_case). However, in Symfony applications is common to use CamelCase to
463
+ name properties (even though the `PSR-1 standard `_ doesn't recommend any
464
+ specific case for property names).
464
465
465
466
Symfony provides a built-in name converter designed to transform between
466
467
snake_case and CamelCased styles during serialization and deserialization
@@ -994,6 +995,7 @@ Learn more
994
995
A popular alternative to the Symfony Serializer Component is the third-party
995
996
library, `JMS serializer `_ (released under the Apache license, so incompatible with GPLv2 projects).
996
997
998
+ .. _`PSR-1 standard` : http://www.php-fig.org/psr/psr-1/
997
999
.. _`JMS serializer` : https://github.com/schmittjoh/serializer
998
1000
.. _Packagist : https://packagist.org/packages/symfony/serializer
999
1001
.. _RFC3339 : https://tools.ietf.org/html/rfc3339#section-5.8
Original file line number Diff line number Diff line change @@ -299,7 +299,6 @@ you can extend your test from
299
299
$kernel->boot();
300
300
301
301
$application = new Application($kernel);
302
- $application->add(new CreateUserCommand());
303
302
304
303
$command = $application->find('app:create-user');
305
304
$commandTester = new CommandTester($command);
Original file line number Diff line number Diff line change @@ -290,33 +290,6 @@ in your controllers.
290
290
291
291
For more information about services, see the :doc: `/service_container ` article.
292
292
293
- .. _controller-access-services-directly :
294
-
295
- Accessing the Container Directly
296
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297
-
298
- If you extend the base ``Controller `` class, you can access :ref: `public services <container-public >`
299
- via the :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::get `
300
- method. Here are several common services you might need::
301
-
302
- $templating = $this->get('templating');
303
-
304
- $router = $this->get('router');
305
-
306
- $mailer = $this->get('mailer');
307
-
308
- // you can also fetch parameters
309
- $someParameter = $this->getParameter('some_parameter');
310
-
311
- If you receive an error like:
312
-
313
- .. code-block :: text
314
-
315
- You have requested a non-existent service "my_service_id"
316
-
317
- Check to make sure the service exists (use :ref: `debug:container <container-debug-container >`)
318
- and that it's :ref: `public <container-public >`.
319
-
320
293
.. index ::
321
294
single: Controller; Managing errors
322
295
single: Controller; 404 pages
Original file line number Diff line number Diff line change @@ -231,11 +231,14 @@ the default entity manager (i.e. ``default``) is returned::
231
231
232
232
// ...
233
233
234
+ use Doctrine\ORM\EntityManagerInterface;
235
+
234
236
class UserController extends Controller
235
237
{
236
- public function indexAction()
238
+ public function indexAction(EntityManagerInterface $em )
237
239
{
238
- // All 3 return the "default" entity manager
240
+ // These methods also return the default entity manager, but it's preferred
241
+ // to get it by inyecting EntityManagerInterface in the action method
239
242
$em = $this->getDoctrine()->getManager();
240
243
$em = $this->getDoctrine()->getManager('default');
241
244
$em = $this->get('doctrine.orm.default_entity_manager');
Original file line number Diff line number Diff line change @@ -91,9 +91,7 @@ using a special "tag":
91
91
http://symfony.com/schema/dic/services/services-1.0.xsd" >
92
92
93
93
<services >
94
- <service id =" app.exception_listener"
95
- class =" App\EventListener\ExceptionListener" >
96
-
94
+ <service id =" AppBundle\EventListener\ExceptionListener" >
97
95
<tag name =" kernel.event_listener" event =" kernel.exception" />
98
96
</service >
99
97
</services >
@@ -105,7 +103,7 @@ using a special "tag":
105
103
use App\EventListener\ExceptionListener;
106
104
107
105
$container
108
- ->register('app.exception_listener', ExceptionListener::class)
106
+ ->autowire( ExceptionListener::class)
109
107
->addTag('kernel.event_listener', array('event' => 'kernel.exception'))
110
108
;
111
109
Original file line number Diff line number Diff line change @@ -317,6 +317,12 @@ valid, but whether or not the ``$task`` object is valid after the form has
317
317
applied the submitted data to it. Calling ``$form->isValid() `` is a shortcut
318
318
that asks the ``$task `` object whether or not it has valid data.
319
319
320
+ Before using validation, add support for it in your application:
321
+
322
+ .. code-block :: terminal
323
+
324
+ $ composer require validator
325
+
320
326
Validation is done by adding a set of rules (called constraints) to a class. To
321
327
see this in action, add validation constraints so that the ``task `` field cannot
322
328
be empty and the ``dueDate `` field cannot be empty and must be a valid \D ateTime
Original file line number Diff line number Diff line change @@ -334,7 +334,7 @@ type::
334
334
entry_type
335
335
~~~~~~~~~~
336
336
337
- **type **: ``string `` or :class: `Symfony\\ Component\\ Form\\ FormTypeInterface ` **required **
337
+ **type **: ``string `` or :class: `Symfony\\ Component\\ Form\\ FormTypeInterface ` **default **: Symfony \\ Component \\ Form \\ Extension \\ Core \\ Type \\ TextType
338
338
339
339
This is the field type for each item in this collection (e.g. ``TextType ``,
340
340
``ChoiceType ``, etc). For example, if you have an array of email addresses,
Original file line number Diff line number Diff line change @@ -576,7 +576,7 @@ Generating URLs with Query Strings
576
576
The ``generate() `` method takes an array of wildcard values to generate the URI.
577
577
But if you pass extra ones, they will be added to the URI as a query string::
578
578
579
- $this->get(' router') ->generate('blog', array(
579
+ $this->router->generate('blog', array(
580
580
'page' => 2,
581
581
'category' => 'Symfony'
582
582
));
Original file line number Diff line number Diff line change @@ -980,6 +980,8 @@ Learn more
980
980
:maxdepth: 1
981
981
:glob:
982
982
983
+ /service_container/*
984
+
983
985
.. _`service-oriented architecture` : https://en.wikipedia.org/wiki/Service-oriented_architecture
984
986
.. _`Symfony Standard Edition (version 3.3) services.yaml` : https://github.com/symfony/symfony-standard/blob/3.3/app/config/services.yml
985
987
.. _`glob pattern` : https://en.wikipedia.org/wiki/Glob_(programming)
You can’t perform that action at this time.
0 commit comments