<?php

namespace MyApp\MyAppBundle\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
{
    private 
$debug;

    
/**
     * Constructor
     *
     * @param Boolean $debug Wether to use the debug mode
     */
    
public function  __construct($debug)
    {
        
$this->debug = (Boolean) $debug;
    }

    
/**
     * {@inheritDoc}
     */
    
public function getConfigTreeBuilder()
    {
        
$treeBuilder = new TreeBuilder();
        
$rootNode $treeBuilder->root('my_app');

        
$this->addCacheSection($rootNode);

        return 
$treeBuilder;
    }

    
/**
     * Adds 'cache' configuration.
     *
     * has_offers:
     *     cache:
     *         server:      127.0.0.1
     *         port:        11211
     *         expire:      120
     */
   
private function addCacheSection(ArrayNodeDefinition $node)
    {
        
$node
            
->children()
            ->
arrayNode('cache')
                ->
children()
                    ->
scalarNode('server')->end() //defaultValue('127.0.0.1')->end()
                    
->scalarNode('port')->end() //defaultValue('11211')->end()
                    
->scalarNode('expire')->end() //defaultValue('120')->end()
                
->end()
            ->
end()
        ;
    }

}