@@ -41,15 +41,51 @@ Basic Usage
4141-----------
4242
4343Once installed, this bundle creates a new service called ` security ` in your
44- Symfony application. This service provides lots ot shortcuts for the most common
45- security operations. For example, to get the current application user:
44+ Symfony application. This service provides lots of shortcuts for the most common
45+ security operations. For example, to get the current application user in a
46+ controller:
4647
4748``` php
48- // in a Symfony controller
49+ // in a Symfony standard application
50+ $user = $this->get('security.token_storage')->getToken()->getUser();
51+
52+ // with this bundle
4953$user = $this->get('security')->getUser();
54+ ```
55+
56+ These shortcuts can be used across your application if you inject the ` security `
57+ service. For example, if you define your services in YAML format:
58+
59+ ``` yaml
60+ # app/config/services.yml
61+ services :
62+ app.my_service :
63+ # ...
64+ arguments : ['@security']
65+ ` ` `
66+
67+ Then, update the constructor of your service to get the ` security` service:
68+
69+ ` ` ` php
70+ // src/AppBundle/MyService.php
71+ // ...
72+ use EasyCorp\B undle\E asySecurityBundle\S ecurity\S ecurity;
5073
51- // in a class where the 'security' service has been injected
52- $user = $this->security->getUser();
74+ class MyService
75+ {
76+ private $security;
77+
78+ public function __construct(Security $security)
79+ {
80+ $this->security = $security;
81+ }
82+
83+ public function myMethod()
84+ {
85+ // ...
86+ $user = $this->security->getUser();
87+ }
88+ }
5389` ` `
5490
5591List of Shortcuts
0 commit comments