vendor/globunet/notification-bundle/DependencyInjection/Configuration.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Globunet Project package.
  4.  *
  5.  * Created by Globunet on 10/04/16. <info@globunet.com>
  6.  * Copyright (c) 2015 Globunet Soluciones Tecnológicas, SL. All rights reserved.
  7.  *
  8.  */
  9. namespace Globunet\NotificationBundle\DependencyInjection;
  10. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  11. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  12. use Symfony\Component\Config\Definition\ConfigurationInterface;
  13. /**
  14.  * This is the class that validates and merges configuration from your app/config files
  15.  *
  16.  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
  17.  */
  18. class Configuration implements ConfigurationInterface
  19. {
  20.     /**
  21.      * @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition
  22.      */
  23.     protected $root;
  24.     /**
  25.      * {@inheritDoc}
  26.      */
  27.     public function getConfigTreeBuilder()
  28.     {
  29.         $treeBuilder = new TreeBuilder();
  30.         //$rootNode = $treeBuilder->root('globunet_notification');
  31.         $this->root $treeBuilder->root("globunet_notification");
  32.         $this->initialMail();
  33.         // Push
  34.         $pushNode = new ArrayNodeDefinition('push');
  35.         $this->addSpool($pushNode);
  36.         $this->addAndroid($pushNode);
  37.         $this->addiOS($pushNode);
  38.         $this->addMac($pushNode);
  39.         $this->addBlackberry($pushNode);
  40.         $this->addWindowsphone($pushNode);
  41.         $this->root->append($pushNode);
  42.         return $treeBuilder;
  43.     }
  44.     protected function initialMail(){
  45.         $this->root
  46.             ->children()
  47.                 ->arrayNode('mailer')/*->addDefaultsIfNotSet()*/
  48.                     ->children()
  49.                         ->scalarNode('enable')/*->/*defaultValue("smtp")*/->end()
  50.                     ->end()
  51.                 ->end()
  52.             ->end()
  53.         ;
  54.     }
  55.     /**
  56.      * Android configuration
  57.      */
  58.     protected function addSpool(ArrayNodeDefinition $pushNode)
  59.     {
  60.         $pushNode->
  61.             children()->
  62.                 arrayNode("spool")->
  63.                     children()->
  64.                         scalarNode("path")->defaultValue("%kernel.project_dir%/var/spool/spool_push")->end()->
  65.                     end()->
  66.                 end()->
  67.             end()
  68.         ;
  69.     }
  70.     /**
  71.      * Android configuration
  72.      */
  73.     protected function addAndroid(ArrayNodeDefinition $pushNode)
  74.     {
  75.         $pushNode->
  76.             children()->
  77.                 arrayNode("android")->
  78.                     canBeUnset()->
  79.                     children()->
  80.                         scalarNode("timeout")->defaultValue(5)->end()->
  81.                         // WARNING: These 3 fields as they are, outside of the c2dm array
  82.                         // are deprecrated in favour of using the c2dm array configuration
  83.                         // At present these will be overriden by anything supplied
  84.                         // in the c2dm array
  85.                         scalarNode("username")->defaultValue("")->end()->
  86.                         scalarNode("password")->defaultValue("")->end()->
  87.                         scalarNode("source")->defaultValue("")->end()->
  88.                         arrayNode("c2dm")->
  89.                             canBeUnset()->
  90.                             children()->
  91.                                 scalarNode("username")->isRequired()->end()->
  92.                                 scalarNode("password")->isRequired()->end()->
  93.                                 scalarNode("source")->defaultValue("")->end()->
  94.                             end()->
  95.                         end()->
  96.                         arrayNode("gcm")->
  97.                             canBeUnset()->
  98.                             children()->
  99.                                 scalarNode("api_key")->isRequired()->cannotBeEmpty()->end()->
  100.                                 booleanNode("use_multi_curl")->defaultValue(true)->end()->
  101.                                 booleanNode("dry_run")->defaultFalse()->end()->
  102.                             end()->
  103.                         end()->
  104.                         arrayNode("fcm")->
  105.                             canBeUnset()->
  106.                                 children()->
  107.                                 scalarNode("api_key")->isRequired()->cannotBeEmpty()->end()->
  108.                             end()->
  109.                         end()->
  110.                     end()->
  111.                 end()->
  112.             end()
  113.         ;
  114.     }
  115.     /**
  116.      * iOS configuration
  117.      */
  118.     protected function addiOS(ArrayNodeDefinition $pushNode)
  119.     {
  120.         $this->addApple($pushNode"ios");
  121.     }
  122.     /**
  123.      * Mac configuration
  124.      */
  125.     protected function addMac(ArrayNodeDefinition $pushNode)
  126.     {
  127.         $this->addApple($pushNode"mac");
  128.     }
  129.     /**
  130.      * Generic Apple Configuration
  131.      */
  132.     private function addApple(ArrayNodeDefinition $pushNode$os)
  133.     {
  134.         $config $pushNode->
  135.             children()->
  136.                 arrayNode($os)->
  137.                     children()->
  138.                         scalarNode("timeout")->defaultValue(60)->end()->
  139.                         booleanNode("sandbox")->defaultFalse()->end()->
  140.                         scalarNode("pem")->cannotBeEmpty()->end()->
  141.                         scalarNode("passphrase")->defaultValue("")->end()->
  142.                         scalarNode('json_unescaped_unicode')->defaultFalse();
  143.                         if (method_exists($config,'info')) {
  144.                             $config $config->info('PHP >= 5.4.0 and each messaged must be UTF-8 encoding');
  145.                         }
  146.                         $config->end()->
  147.                     end()->
  148.                 end()->
  149.             end()
  150.         ;
  151.     }
  152.     /**
  153.      * Blackberry configuration
  154.      */
  155.     protected function addBlackberry(ArrayNodeDefinition $pushNode)
  156.     {
  157.         $pushNode->
  158.             children()->
  159.                 arrayNode("blackberry")->
  160.                     children()->
  161.                         scalarNode("timeout")->defaultValue(5)->end()->
  162.                         booleanNode("evaluation")->defaultFalse()->end()->
  163.                         scalarNode("app_id")->isRequired()->cannotBeEmpty()->end()->
  164.                         scalarNode("password")->isRequired()->cannotBeEmpty()->end()->
  165.                     end()->
  166.                 end()->
  167.             end()
  168.         ;
  169.     }
  170.     /**
  171.      * Windows Phone configuration
  172.      */
  173.     protected function addWindowsphone(ArrayNodeDefinition $pushNode)
  174.     {
  175.         $pushNode->
  176.             children()->
  177.                 arrayNode('windowsphone')->
  178.                     children()->
  179.                         scalarNode("timeout")->defaultValue(5)->end()->
  180.                     end()->
  181.                 end()->
  182.             end()
  183.         ;
  184.     }
  185. }