An overview of the main features of the symfony/dependency-injection package.
Clone the repository:
$ git clone https://github.com/jlttt/sdic.git
Install dependencies:
$ cd sdic
$ composer install
Run the application:
$ ./bin/deploy
Tags allow to navigate between the different parts. For example, to go to the code of the default application, use:
$ git checkout start
Tag: start
The default application without depency injection container.
To automate deployment of customer clouds, one ask a CloudProvider
service the list of existing clouds (throw an API), select one of them and deploy it thanks to the Jenkins API.
Tag: dependency-injection-container
Basic use of the dependency injection container.
Useful objects and methods:
Definition
: Definition of a service, creation for a FQCNReference
: Reference to a service, creation from a service id.ContainerBuilder::setDefintion(serviceId, definition)
: register a definitionContainerBuilder::register(serviceId, fqcn)
: register a class as definitionDefinition::setArgument(reference)
: register a dependency (as a service reference) to a definition
Tag: autowiring
Automatic depency injection. Argument setting is no more needed, but container needs to be compiled.
Useful methods:
Definition::setAutowired
: active/unactive autowiring for the serviceContainerBuilder::compile
: Compilation of the container
Tag: autoconfiguration
Exploration of the application to find services (thanks to PSR-4). Require the symfony/config package and the container needs to be compiled.
Useful objects and methods:
FileLoader
,FileLoader::registerClasses(baseDefinition, namespace, path)
: register services of a namespace from a base definitionDefinition::setAutoconfigured
: active/unactive autoconfiguration
Tag: config-file
Use the config component to move container configuration in a specific file.
Useful methods:
FileLoader::load(configFile)
: a context with preset variables ($container
,$loader
,...) is provided to the configuration file
Tag: filter-feature
To go deeper, one needs to extend the initial application by allowing to filter clouds.
Tag: scalar-values-injection
Container injects classes. It can also inject scalar values (string, array, int,...).
Useful methods:
ContainerBuilder::setParameter(id, scalarValue)
: register a scalar valueContainerBuilder::addArgument('%id%')
: use a registered scalar value (note that the id is surrounded by%
)
Tag: add-method-call
A service definition can be enhanced by registring method calls to play right after the service instanciation.
Useful methods:
Definition::addMethodCall(method, arguments)
Tag: tags-and-compiler-pass
A service definition can be enhanced by registering method calls to play right after the service instanciation.
Useful class and methods:
CompilerPassInterface
: contract for a new compiler passContainerBuilder::addCompilerPass(compilerPass)
: register the given compiler pass to be run at compilation timeContainerBuilder::registerForAutoconfiguration(fqcn)
: prepare the autoconfiguration to extract all classes extending fqcnContainerBuilder::findTaggedServiceIds(tag)
: retrieve services by tagDefinition::addTag(tag)
: tag a service
Tag: yaml-config-file
Use Yaml format for configuration file. Require the symfony/yaml package
Useful objects:
YamlFileLoader
Tag: container-dump
The container can be cached to avoid compilation at each application run.
Useful objects and methods:
PhpDumper::dump(options)
: dump as PHP class