FOS\UserBundle\Security\Encoder\EncoderFactory::getEncoder PHP Method

getEncoder() public method

See also: Symfony\Component\Security\Core\Encoder\EncoderFactory::getEncoder()
public getEncoder ( Symfony\Component\Security\Core\User\AccountInterface $account )
$account Symfony\Component\Security\Core\User\AccountInterface
    public function getEncoder(AccountInterface $account)
    {
        if (!$account instanceof UserInterface) {
            return $this->genericFactory->getEncoder($account);
        }
        if (isset($this->encoders[$algorithm = $account->getAlgorithm()])) {
            return $this->encoders[$algorithm];
        }
        return $this->encoders[$algorithm] = $this->createEncoder($algorithm);
    }

Usage Example

 public function testGetEncoderWithGenericAccount()
 {
     $genericFactory = $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface');
     $encoder = $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface');
     $genericFactory->expects($this->once())->method('getEncoder')->will($this->returnValue($encoder));
     $factory = new EncoderFactory(null, false, 1, $genericFactory);
     $this->assertSame($encoder, $factory->getEncoder($this->getMock('Symfony\\Component\\Security\\Core\\User\\AccountInterface')));
 }