Last active
September 11, 2017 10:02
-
-
Save eghojansu/7c55e268fed7e9ae4ba9826ccf147fd7 to your computer and use it in GitHub Desktop.
Snippet for post Install nelmio/alice di Framework Symfony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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