/DependencyInjection/Security/Factory/FacebookFactory.php

http://github.com/FriendsOfSymfony/FOSFacebookBundle · PHP · 78 lines · 54 code · 14 blank · 10 comment · 1 complexity · e22247c615a518a90486ddb41e796375 MD5 · raw file

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