<?php/* * This file is part of the Globunet Project package. * * Created by Globunet on 10/04/16. <info@globunet.com> * Copyright (c) 2015 Globunet Soluciones Tecnológicas, SL. All rights reserved. * */namespace Globunet\NotificationBundle\DependencyInjection;use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;use Symfony\Component\Config\Definition\Builder\TreeBuilder;use Symfony\Component\Config\Definition\ConfigurationInterface;/** * This is the class that validates and merges configuration from your app/config files * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} */class Configuration implements ConfigurationInterface{ /** * @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition */ protected $root; /** * {@inheritDoc} */ public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); //$rootNode = $treeBuilder->root('globunet_notification'); $this->root = $treeBuilder->root("globunet_notification"); $this->initialMail(); // Push $pushNode = new ArrayNodeDefinition('push'); $this->addSpool($pushNode); $this->addAndroid($pushNode); $this->addiOS($pushNode); $this->addMac($pushNode); $this->addBlackberry($pushNode); $this->addWindowsphone($pushNode); $this->root->append($pushNode); return $treeBuilder; } protected function initialMail(){ $this->root ->children() ->arrayNode('mailer')/*->addDefaultsIfNotSet()*/ ->children() ->scalarNode('enable')/*->/*defaultValue("smtp")*/->end() ->end() ->end() ->end() ; } /** * Android configuration */ protected function addSpool(ArrayNodeDefinition $pushNode) { $pushNode-> children()-> arrayNode("spool")-> children()-> scalarNode("path")->defaultValue("%kernel.project_dir%/var/spool/spool_push")->end()-> end()-> end()-> end() ; } /** * Android configuration */ protected function addAndroid(ArrayNodeDefinition $pushNode) { $pushNode-> children()-> arrayNode("android")-> canBeUnset()-> children()-> scalarNode("timeout")->defaultValue(5)->end()-> // WARNING: These 3 fields as they are, outside of the c2dm array // are deprecrated in favour of using the c2dm array configuration // At present these will be overriden by anything supplied // in the c2dm array scalarNode("username")->defaultValue("")->end()-> scalarNode("password")->defaultValue("")->end()-> scalarNode("source")->defaultValue("")->end()-> arrayNode("c2dm")-> canBeUnset()-> children()-> scalarNode("username")->isRequired()->end()-> scalarNode("password")->isRequired()->end()-> scalarNode("source")->defaultValue("")->end()-> end()-> end()-> arrayNode("gcm")-> canBeUnset()-> children()-> scalarNode("api_key")->isRequired()->cannotBeEmpty()->end()-> booleanNode("use_multi_curl")->defaultValue(true)->end()-> booleanNode("dry_run")->defaultFalse()->end()-> end()-> end()-> arrayNode("fcm")-> canBeUnset()-> children()-> scalarNode("api_key")->isRequired()->cannotBeEmpty()->end()-> end()-> end()-> end()-> end()-> end() ; } /** * iOS configuration */ protected function addiOS(ArrayNodeDefinition $pushNode) { $this->addApple($pushNode, "ios"); } /** * Mac configuration */ protected function addMac(ArrayNodeDefinition $pushNode) { $this->addApple($pushNode, "mac"); } /** * Generic Apple Configuration */ private function addApple(ArrayNodeDefinition $pushNode, $os) { $config = $pushNode-> children()-> arrayNode($os)-> children()-> scalarNode("timeout")->defaultValue(60)->end()-> booleanNode("sandbox")->defaultFalse()->end()-> scalarNode("pem")->cannotBeEmpty()->end()-> scalarNode("passphrase")->defaultValue("")->end()-> scalarNode('json_unescaped_unicode')->defaultFalse(); if (method_exists($config,'info')) { $config = $config->info('PHP >= 5.4.0 and each messaged must be UTF-8 encoding'); } $config->end()-> end()-> end()-> end() ; } /** * Blackberry configuration */ protected function addBlackberry(ArrayNodeDefinition $pushNode) { $pushNode-> children()-> arrayNode("blackberry")-> children()-> scalarNode("timeout")->defaultValue(5)->end()-> booleanNode("evaluation")->defaultFalse()->end()-> scalarNode("app_id")->isRequired()->cannotBeEmpty()->end()-> scalarNode("password")->isRequired()->cannotBeEmpty()->end()-> end()-> end()-> end() ; } /** * Windows Phone configuration */ protected function addWindowsphone(ArrayNodeDefinition $pushNode) { $pushNode-> children()-> arrayNode('windowsphone')-> children()-> scalarNode("timeout")->defaultValue(5)->end()-> end()-> end()-> end() ; }}