Skip to content

Instantly share code, notes, and snippets.

@hacfi
Created February 24, 2013 21:57
Show Gist options
  • Save hacfi/5025876 to your computer and use it in GitHub Desktop.
Save hacfi/5025876 to your computer and use it in GitHub Desktop.
<?php
namespace hacfi\AppBundle\DependencyInjection\Security\Factory;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
/**
* hacfi\AppBundle\DependencyInjection\Security\Factory\FacebookFactory
*/
class FacebookFactory extends AbstractFactory
{
/* from the cookbook...don't use it anymore because of AbstractFactory doing the same thing with the other methods
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
$provider = 'security.authentication.provider.facebook.' . $id;
$container
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.facebook'))
->replaceArgument(0, new Reference($userProvider))
;
$listenerId = 'security.authentication.listener.facebook.' . $id;
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.facebook'));
return array($provider, $listenerId, $defaultEntryPoint);
}
*/
public function getPosition()
{
return 'form';
}
public function getKey()
{
return 'facebook';
}
public function addConfiguration(NodeDefinition $node)
{
parent::addConfiguration($node);
}
/**
* Subclasses must return the id of a service which implements the
* AuthenticationProviderInterface.
*
* @param ContainerBuilder $container
* @param string $id The unique id of the firewall
* @param array $config The options array for this listener
* @param string $userProviderId The id of the user provider
*
* @return string never null, the id of the authentication provider
*/
protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
{
$provider = 'security.authentication.provider.facebook.'.$id;
$container
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.facebook'))
->replaceArgument(0, new Reference($userProviderId))
//->replaceArgument(2, $id)
;
return $provider;
}
protected function createListener($container, $id, $config, $userProvider)
{
$listenerId = $this->getListenerId();
$listener = new DefinitionDecorator($listenerId);
$listener->replaceArgument(4, $id);
$listener->replaceArgument(5, new Reference($this->createAuthenticationSuccessHandler($container, $id, $config)));
$listener->replaceArgument(6, new Reference($this->createAuthenticationFailureHandler($container, $id, $config)));
$listener->replaceArgument(7, array_intersect_key($config, $this->options));
$listenerId .= '.'.$id;
$container->setDefinition($listenerId, $listener);
return $listenerId;
}
/**
* Subclasses must return the id of the listener template.
*
* Listener definitions should inherit from the AbstractAuthenticationListener
* like this:
*
* <service id="my.listener.id"
* class="My\Concrete\Classname"
* parent="security.authentication.listener.abstract"
* abstract="true" />
*
* In the above case, this method would return "my.listener.id".
*
* @return string
*/
protected function getListenerId()
{
return 'security.authentication.listener.facebook';
}
protected function isRememberMeAware($config)
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment