Skip to content

Instantly share code, notes, and snippets.

@eghojansu
Last active September 11, 2017 10:02
Show Gist options
  • Save eghojansu/7c55e268fed7e9ae4ba9826ccf147fd7 to your computer and use it in GitHub Desktop.
Save eghojansu/7c55e268fed7e9ae4ba9826ccf147fd7 to your computer and use it in GitHub Desktop.
Snippet for post Install nelmio/alice di Framework Symfony
<?php
// src/AppBundle/DataFixtures/ORM/CustomProvider/CustomFakerProvider.php
namespace AppBundle\DataFixtures\ORM\CustomProvider;
use AppBundle\Utils\Config;
use Faker\Generator;
use Faker\Provider\Base;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class CustomFakerProvider extends Base
{
/** @var UserPasswordEncoderInterface */
private $passwordEncoder;
public function __construct(Generator $generator, UserPasswordEncoderInterface $passwordEncoder)
{
parent::__construct($generator);
$this->passwordEncoder = $passwordEncoder;
}
/**
* @param UserInterface $user
* @param string $plainPassword
*
* @return string encoded password
*/
public function myPassword(UserInterface $user, $plainPassword) {
return $this->passwordEncoder->encodePassword($user, $plainPassword);
}
/**
* @return string
*/
public function myGender()
{
$genders = Config::getGenders();
return $genders[array_rand($genders)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment