SHARE
TWEET

FOSMessageExtension

a guest Apr 6th, 2018 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace FOS\MessageBundle\DependencyInjection;
  4.  
  5. use Symfony\Component\Config\Definition\Processor;
  6. use Symfony\Component\DependencyInjection\Reference;
  7. use Symfony\Component\DependencyInjection\Alias;
  8. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  9. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  10. use Symfony\Component\DependencyInjection\ContainerBuilder;
  11. use Symfony\Component\Config\FileLocator;
  12.  
  13. class FOSMessageExtension extends Extension
  14. {
  15.     public function load(array $configs, ContainerBuilder $container)
  16.     {
  17.         $processor = new Processor();
  18.         $configuration = new Configuration();
  19.  
  20.         $config = $processor->processConfiguration($configuration, $configs);
  21.  
  22.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  23.  
  24.         if (!in_array(strtolower($config['db_driver']), array('orm', 'mongodb'))) {
  25.             throw new \InvalidArgumentException(sprintf('Invalid db driver "%s".', $config['db_driver']));
  26.         }
  27.  
  28.         $loader->load(sprintf('%s.xml', $config['db_driver']));
  29.         $loader->load('config.xml');
  30.         $loader->load('form.xml');
  31.         $loader->load('validator.xml');
  32.         $loader->load('spam_detection.xml');
  33.  
  34.         $container->setParameter('fos_message.message_class', $config['message_class']);
  35.         $container->setParameter('fos_message.thread_class', $config['thread_class']);
  36.  
  37.         $container->setParameter('fos_message.new_thread_form.model', $config['new_thread_form']['model']);
  38.         $container->setParameter('fos_message.new_thread_form.name', $config['new_thread_form']['name']);
  39.         $container->setParameter('fos_message.reply_form.model', $config['reply_form']['model']);
  40.         $container->setParameter('fos_message.reply_form.name', $config['reply_form']['name']);
  41.  
  42.         $container->setAlias('fos_message.message_manager', new Alias($config['message_manager'], true));
  43.         $container->setAlias('fos_message.thread_manager', new Alias($config['thread_manager'], true));
  44.  
  45.         $container->setAlias('fos_message.sender', new Alias($config['sender'], true));
  46.         $container->setAlias('fos_message.composer', new Alias($config['composer'], true));
  47.         $container->setAlias('fos_message.provider', new Alias($config['provider'], true));
  48.         $container->setAlias('fos_message.participant_provider', new Alias($config['participant_provider'], true));
  49.         $container->setAlias('fos_message.authorizer', new Alias($config['authorizer'], true));
  50.         $container->setAlias('fos_message.message_reader', new Alias($config['message_reader'], true));
  51.         $container->setAlias('fos_message.thread_reader', new Alias($config['thread_reader'], true));
  52.         $container->setAlias('fos_message.deleter', new Alias($config['deleter'], true));
  53.         $container->setAlias('fos_message.spam_detector', new Alias($config['spam_detector'], true));
  54.         $container->setAlias('fos_message.twig_extension', new Alias($config['twig_extension'], true));
  55.  
  56.         // BC management
  57.         $newThreadFormType = $config['new_thread_form']['type'];
  58.         $replyFormType = $config['reply_form']['type'];
  59.  
  60.         if (!class_exists($newThreadFormType)) {
  61.             @trigger_error('Using a service reference in configuration key "fos_message.new_thread_form.type" is deprecated since version 1.2 and will be removed in 2.0. Use the class name of your form type instead.', E_USER_DEPRECATED);
  62.  
  63.             // Old syntax (service reference)
  64.             $container->setAlias('fos_message.new_thread_form.type', new Alias($newThreadFormType, true));
  65.         } else {
  66.             // New syntax (class name)
  67.             $container->getDefinition('fos_message.new_thread_form.factory.default')
  68.                 ->replaceArgument(1, $newThreadFormType);
  69.         }
  70.  
  71.         if (!class_exists($replyFormType)) {
  72.             @trigger_error('Using a service reference in configuration key "fos_message.reply_form.type" is deprecated since version 1.2 and will be removed in 2.0. Use the class name of your form type instead.', E_USER_DEPRECATED);
  73.  
  74.             // Old syntax (service reference)
  75.             $container->setAlias('fos_message.reply_form.type', new Alias($replyFormType, true));
  76.         } else {
  77.             // New syntax (class name)
  78.             $container->getDefinition('fos_message.reply_form.factory.default')
  79.                 ->replaceArgument(1, $replyFormType);
  80.         }
  81.  
  82.         $container->setAlias('fos_message.new_thread_form.factory', new Alias($config['new_thread_form']['factory'], true));
  83.         $container->setAlias('fos_message.new_thread_form.handler', new Alias($config['new_thread_form']['handler'], true));
  84.         $container->setAlias('fos_message.reply_form.factory', new Alias($config['reply_form']['factory'], true));
  85.         $container->setAlias('fos_message.reply_form.handler', new Alias($config['reply_form']['handler'], true));
  86.  
  87.         $container->setAlias('fos_message.search_query_factory', new Alias($config['search']['query_factory'], true));
  88.         $container->setAlias('fos_message.search_finder', new Alias($config['search']['finder'], true));
  89.         $container->getDefinition('fos_message.search_query_factory.default')
  90.             ->replaceArgument(1, $config['search']['query_parameter']);
  91.  
  92.         $container->getDefinition('fos_message.recipients_data_transformer')
  93.             ->replaceArgument(0, new Reference($config['user_transformer']));
  94.     }
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top