Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
[Factory] Implement directly the interface instead of extend from the…
Browse files Browse the repository at this point in the history
… AbstractFactory
  • Loading branch information
Maks3w committed Jun 8, 2012
1 parent 164cfcb commit 87e4bee
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions Security/Factory/LdapFactory.php
Expand Up @@ -2,13 +2,24 @@


namespace FR3D\LdapBundle\Security\Factory; namespace FR3D\LdapBundle\Security\Factory;


use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;


class LdapFactory extends AbstractFactory class LdapFactory implements SecurityFactoryInterface
{ {
public function create(ContainerBuilder $container, $id, $config, $userProviderId, $defaultEntryPointId)
{
// authentication provider
$authProviderId = $this->createAuthProvider($container, $id, $config, $userProviderId);

// authentication listener
$listenerId = $this->createListener($container, $id, $config, $userProviderId);

return array($authProviderId, $listenerId, $defaultEntryPointId);
}


public function getPosition() public function getPosition()
{ {
Expand All @@ -20,21 +31,38 @@ public function getKey()
return 'fr3d_ldap'; return 'fr3d_ldap';
} }


protected function getListenerId() public function addConfiguration(NodeDefinition $node)
{ {
return 'security.authentication.listener.form'; // Without Configuration
} }


protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId) protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
{ {
$provider = 'fr3d_ldap.security.authentication.provider.' . $id; $provider = 'fr3d_ldap.security.authentication.provider';
$providerId = $provider . '.' . $id;

$container
->setDefinition($providerId, new DefinitionDecorator($provider))
->replaceArgument(1, $id) // Provider Key
->replaceArgument(2, new Reference($userProviderId)) // User Provider
;

return $providerId;
}

protected function createListener(ContainerBuilder $container, $id, $config, $userProvider)
{
$listenerId = 'security.authentication.listener.form';

$listener = new DefinitionDecorator($listenerId);
$listener->replaceArgument(4, $id);
$listener->replaceArgument(5, $config);


$listenerId .= '.' . $id;
$container $container
->setDefinition($provider, new DefinitionDecorator('fr3d_ldap.security.authentication.provider')) ->setDefinition($listenerId, $listener)
->replaceArgument(1, $id) // Provider Key
->replaceArgument(2, new Reference($userProviderId)) // User Provider
; ;


return $provider; return $listenerId;
} }
} }

0 comments on commit 87e4bee

Please sign in to comment.