Skip to content

Latest commit

 

History

History
71 lines (58 loc) · 2.25 KB

Dependency-Injection-Extension.md

File metadata and controls

71 lines (58 loc) · 2.25 KB

Meritoo Common Bundle

Common & useful classes, resources, extensions. Based on Symfony framework.

Dependency Injection Extension

Introduction

Configuration parameters are loaded by Meritoo\CommonBundle\DependencyInjection\Configuration class that implements Symfony\Component\Config\Definition\ConfigurationInterface and uses Symfony\Component\Config\Definition\Builder\TreeBuilder to build structure of configuration parameters.

If the Dependency Injection extension class extends Meritoo\CommonBundle\DependencyInjection\Base\BaseExtension class, each parameter is automatically loaded into container with name based on nodes from structure of configuration separated by ..

Example

// A piece of getConfigTreeBuilder() method from Configuration class
$rootNode = $treeBuilder->root('my_main_node');

$rootNode
    ->addDefaultsIfNotSet()
    ->children()
        ->arrayNode('lorem')
            ->addDefaultsIfNotSet()
            ->children()
                ->scalarNode('ipsum')
                    ->defaultValue(1234)
                    ->cannotBeEmpty()
                ->end()
            ->end()
        ->end()
        ->scalarNode('dolor')
            ->defaultValue('')
        ->end()
        ->scalarNode('sit')
        ->end()
    ->end()
;
# Parameters loaded into container (with values based on defaults)

my_main_node.lorem.ipsum # Value: 1234
my_main_node.dolor       # Value: ""
my_main_node.sit         # Value: null

More

  1. Configuration
  2. Dependency Injection Extension
  3. Descriptor of application
  4. Descriptor of bundle
  5. Descriptors of bundles
  6. Services:
  7. Tests
  8. Translations
  9. Twig extensions:

‹ Back to Readme