Commit 0c7f86f1 authored by Mat's avatar Mat
Browse files

fixture user

parent 9691c361
<?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();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment