Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
potage
Commits
0c7f86f1
Commit
0c7f86f1
authored
Aug 23, 2018
by
Mat
Browse files
fixture user
parent
9691c361
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/PotageBundle/DataFixtures/ORM/LoadUser.php
0 → 100755
View file @
0c7f86f1
<?php
namespace
PotageBundle\DataFixtures\ORM
;
use
Doctrine\Common\DataFixtures\FixtureInterface
;
use
Doctrine\Common\Persistence\ObjectManager
;
use
PotageBundle\Entity\User
;
use
Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface
;
class
LoadUser
implements
FixtureInterface
{
private
$encoder
;
/**
* LoadUser constructor.
* @param UserPasswordEncoderInterface $encoder
*/
public
function
__construct
(
UserPasswordEncoderInterface
$encoder
)
{
$this
->
encoder
=
$encoder
;
}
/**
* @param ObjectManager $manager
*/
public
function
load
(
ObjectManager
$manager
)
{
$users
=
array
(
array
(
'mathieu'
,
'1234'
,
'jaummathieu@collectif.net'
,
'ROLE_SUPER_ADMIN'
),
array
(
'mat'
,
'1234'
,
'mat@collectif.net'
,
'ROLE_ADMIN'
),
array
(
'enzo'
,
'1234'
,
'sudo_112@no-log.org'
,
'ROLE_USER'
)
);
foreach
(
$users
as
$value
)
{
$user
=
new
User
;
$user
->
setUsername
(
$value
[
0
]);
$password
=
$this
->
encoder
->
encodePassword
(
$user
,
$value
[
1
]);
$user
->
setPassword
(
$password
);
$user
->
setEmail
(
$value
[
2
]);
$user
->
setRoles
(
array
(
$value
[
3
]));
$manager
->
persist
(
$user
);
}
$manager
->
flush
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment