]> Raphaƫl G. Git Repositories - userbundle/blob - README.md
Add note about normalisation prevention
[userbundle] / README.md
1 Installation
2 ============
3
4 Applications that use Symfony Flex
5 ----------------------------------
6
7 Add bundle custom repository to your project's `composer.json` file:
8
9 ```json
10 {
11 ...,
12 "repositories": [
13 {
14 "type": "package",
15 "package": {
16 "name": "rapsys/userbundle",
17 "version": "dev-master",
18 "source": {
19 "type": "git",
20 "url": "https://git.rapsys.eu/userbundle",
21 "reference": "master"
22 },
23 "autoload": {
24 "psr-4": {
25 "Rapsys\\UserBundle\\": ""
26 }
27 },
28 "require": {
29 "doctrine/doctrine-bundle": "^1.12",
30 "rapsys/packbundle": "dev-master",
31 "symfony/flex": "^1.5",
32 "symfony/form": "^4.4",
33 "symfony/framework-bundle": "^4.4",
34 "symfony/security-bundle": "^4.4",
35 "symfony/validator": "^4.4"
36 }
37 }
38 }
39 ],
40 ...
41 }
42 ```
43
44 Then open a command console, enter your project directory and execute:
45
46 ```console
47 $ composer require rapsys/userbundle dev-master
48 ```
49
50 Applications that don't use Symfony Flex
51 ----------------------------------------
52
53 ### Step 1: Download the Bundle
54
55 Open a command console, enter your project directory and execute the
56 following command to download the latest stable version of this bundle:
57
58 ```console
59 $ composer require rapsys/userbundle dev-master
60 ```
61
62 This command requires you to have Composer installed globally, as explained
63 in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
64 of the Composer documentation.
65
66 ### Step 2: Enable the Bundle
67
68 Then, enable the bundle by adding it to the list of registered bundles
69 in the `app/AppKernel.php` file of your project:
70
71 ```php
72 <?php
73 // app/AppKernel.php
74
75 // ...
76 class AppKernel extends Kernel
77 {
78 public function registerBundles()
79 {
80 $bundles = array(
81 // ...
82 new Rapsys\UserBundle\RapsysUserBundle(),
83 );
84
85 // ...
86 }
87
88 // ...
89 }
90 ```
91
92 ### Step 3: Configure the Bundle
93
94 Setup configuration file `config/packages/rapsys_user.yaml` with the following
95 content available in `Rapsys/UserBundle/Resources/config/packages/rapsys_user.yaml`:
96
97 ```yaml
98 #Doctrine configuration
99 doctrine:
100 #Orm configuration
101 orm:
102 #Force resolution of UserBundle entities to CustomBundle one
103 #XXX: without these lines, relations are lookup in parent namespace ignoring CustomBundle extension
104 resolve_target_entities:
105 Rapsys\UserBundle\Entity\Group: 'CustomBundle\Entity\Group'
106 Rapsys\UserBundle\Entity\Civility: 'CustomBundle\Entity\Civility'
107 Rapsys\UserBundle\Entity\User: 'CustomBundle\Entity\User'
108
109 #RapsysUser configuration
110 rapsys_user:
111 #Class replacement
112 class:
113 group: 'CustomBundle\Entity\Group'
114 civility: 'CustomBundle\Entity\Civility'
115 user: 'CustomBundle\Entity\User'
116 #Default replacement
117 default:
118 group: [ 'User' ]
119 civility: 'Mister'
120 #Route replacement
121 route:
122 index:
123 name: 'custom_index'
124
125 #Service configuration
126 services:
127 #Register security context service
128 rapsys_user.access_decision_manager:
129 class: 'Symfony\Component\Security\Core\Authorization\AccessDecisionManager'
130 public: true
131 arguments: [ [ '@security.access.role_hierarchy_voter' ] ]
132 #Register default controller
133 Rapsys\UserBundle\Controller\DefaultController:
134 arguments: [ '@service_container', '@router', '@translator' ]
135 autowire: true
136 tags: [ 'controller.service_arguments' ]
137 #Register Authentication success handler
138 security.authentication.success_handler:
139 class: 'Rapsys\UserBundle\Handler\AuthenticationSuccessHandler'
140 arguments: [ '@router', {} ]
141 #Register Authentication failure handler
142 security.authentication.failure_handler:
143 class: 'Rapsys\UserBundle\Handler\AuthenticationFailureHandler'
144 arguments: [ '@http_kernel', '@security.http_utils', {}, '@logger', '@service_container', '@router', '@rapsys_pack.slugger_util']
145 #Register logout success handler
146 security.logout.success_handler:
147 class: 'Rapsys\UserBundle\Handler\LogoutSuccessHandler'
148 arguments: [ '@service_container', '/', '@router' ]
149 #Register security user checker
150 security.user_checker:
151 class: 'Rapsys\UserBundle\Checker\UserChecker'
152 ```
153
154 Open a command console, enter your project directory and execute the following
155 command to see default bundle configuration:
156
157 ```console
158 $ php bin/console config:dump-reference RapsysUserBundle
159 ```
160
161 Open a command console, enter your project directory and execute the following
162 command to see current bundle configuration:
163
164 ```console
165 $ php bin/console debug:config RapsysUserBundle
166 ```
167
168 ### Step 4: Setup custom bundle entities
169
170 Setup configuration file `CustomBundle/Resources/config/doctrine/User.orm.yml` with the
171 following content:
172
173 ```yaml
174 CustomBundle\Entity\User:
175 type: entity
176 #repositoryClass: CustomBundle\Repository\UserRepository
177 table: users
178 associationOverride:
179 groups:
180 joinTable:
181 name: users_groups
182 joinColumns:
183 id:
184 name: user_id
185 inverseJoinColumns:
186 id:
187 name: group_id
188 ```
189
190 Setup configuration file `Resources/config/doctrine/Group.orm.yml` with the
191 following content:
192
193 ```yaml
194 CustomBundle\Entity\Group:
195 type: entity
196 #repositoryClass: CustomBundle\Repository\GroupRepository
197 table: groups
198 manyToMany:
199 users:
200 targetEntity: Rapsys\AirBundle\Entity\User
201 mappedBy: groups
202 ```
203
204 Setup configuration file `Resources/config/doctrine/Civility.orm.yml` with the
205 following content:
206
207 ```yaml
208 CustomBundle\Entity\Civility:
209 type: entity
210 #repositoryClass: CustomBundle\Repository\CivilityRepository
211 table: civilities
212 oneToMany:
213 users:
214 targetEntity: User
215 mappedBy: civility
216 ```
217
218 Setup entity file `CustomBundle/Entity/User.php` with the following content:
219
220 ```php
221 <?php
222
223 namespace CustomBundle\Entity;
224
225 use Rapsys\UserBundle\Entity\User as BaseUser;
226
227 class User extends BaseUser {}
228 ```
229
230 Setup entity file `CustomBundle/Entity/Group.php` with the following content:
231
232 ```php
233 <?php
234
235 namespace CustomBundle\Entity;
236
237 use Rapsys\GroupBundle\Entity\Group as BaseGroup;
238
239 class Group extends BaseGroup {}
240 ```
241
242 Setup entity file `CustomBundle/Entity/Civility.php` with the following content:
243
244 ```php
245 <?php
246
247 namespace CustomBundle\Entity;
248
249 use Rapsys\CivilityBundle\Entity\Civility as BaseCivility;
250
251 class Civility extends BaseCivility {}
252 ```