/DependencyInjection/Security/Factory/FacebookFactory.php
PHP | 78 lines | 54 code | 14 blank | 10 comment | 1 complexity | e22247c615a518a90486ddb41e796375 MD5 | raw file
1<?php 2 3/* 4 * This file is part of the FOSFacebookBundle package. 5 * 6 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace FOS\FacebookBundle\DependencyInjection\Security\Factory; 13 14use Symfony\Component\DependencyInjection\ContainerBuilder; 15use Symfony\Component\DependencyInjection\Reference; 16use Symfony\Component\DependencyInjection\DefinitionDecorator; 17use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory; 18 19class FacebookFactory extends AbstractFactory 20{ 21 public function __construct() 22 { 23 $this->addOption('display', 'page'); 24 $this->addOption('app_url'); 25 $this->addOption('server_url'); 26 $this->addOption('create_user_if_not_exists', false); 27 $this->addOption('redirect_to_facebook_login', true); 28 } 29 30 public function getPosition() 31 { 32 return 'pre_auth'; 33 } 34 35 public function getKey() 36 { 37 return 'fos_facebook'; 38 } 39 40 protected function getListenerId() 41 { 42 return 'fos_facebook.security.authentication.listener'; 43 } 44 45 protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId) 46 { 47 $authProviderId = 'fos_facebook.auth.'.$id; 48 49 $definition = $container 50 ->setDefinition($authProviderId, new DefinitionDecorator('fos_facebook.auth')) 51 ->replaceArgument(0, $id); 52 53 // with user provider 54 if (isset($config['provider'])) { 55 $definition 56 ->addArgument(new Reference($userProviderId)) 57 ->addArgument(new Reference('security.user_checker')) 58 ->addArgument($config['create_user_if_not_exists']) 59 ; 60 } 61 62 return $authProviderId; 63 } 64 65 protected function createEntryPoint($container, $id, $config, $defaultEntryPointId) 66 { 67 $entryPointId = 'fos_facebook.security.authentication.entry_point.'.$id; 68 $container 69 ->setDefinition($entryPointId, new DefinitionDecorator('fos_facebook.security.authentication.entry_point')) 70 ->replaceArgument(1, $config) 71 ; 72 73 // set options to container for use by other classes 74 $container->setParameter('fos_facebook.options.'.$id, $config); 75 76 return $entryPointId; 77 } 78}