Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Factory] Implement directly the interface instead of extend from the…

… AbstractFactory
  • Loading branch information...
commit 87e4beee927fc94c86ac579e60eb366fdb734a2f 1 parent 164cfcb
@Maks3w authored
Showing with 37 additions and 9 deletions.
  1. +37 −9 Security/Factory/LdapFactory.php
View
46 Security/Factory/LdapFactory.php
@@ -2,13 +2,24 @@
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\DefinitionDecorator;
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()
{
@@ -20,21 +31,38 @@ public function getKey()
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)
{
- $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
- ->setDefinition($provider, new DefinitionDecorator('fr3d_ldap.security.authentication.provider'))
- ->replaceArgument(1, $id) // Provider Key
- ->replaceArgument(2, new Reference($userProviderId)) // User Provider
+ ->setDefinition($listenerId, $listener)
;
- return $provider;
+ return $listenerId;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.