WHAT IS DEPENDENCY INJECTION
WWW.GROSSUM.COM
Dependency injection is a software design pattern in which one or more dependencies (or services) are injected, or passed by reference, into a dependent object (or client) and are made part of the client's state. The pattern separates the creation of a client's dependencies from its own behavior, which allows program designs to be loosely coupled and to follow the dependency inversion and single responsibility principles.
It directly contrasts with the service locator pattern, which allows clients to know about the system they use to find dependencies
SYMFONY CAFÉ KYIV
INTRODUCTION TO PARAMETERS
• Parameters in Configuration Files • Array Parameters • Constants as Parameters • PHP Keywords in XML
WWW.GROSSUM.COM SYMFONY CAFÉ KYIV
WORKING WITH CONTAINER SERVICE DEFINITIONS
• Getting and Setting Service Definitions:
• Class
WWW.GROSSUM.COM
$container->hasDefinition($serviceId); $container->getDefinition($serviceId); $container->findDefinition($serviceId); $container->setDefinition($id, $definition);
$definition->getClass(); $definition->setClass($class); // Fully qualified class name as string
SYMFONY CAFÉ KYIV
WORKING WITH CONTAINER SERVICE DEFINITIONS
• Constructor Arguments
• Method Calls
WWW.GROSSUM.COM
$definition->getArguments(); $definition->getArgument($index); $definition->addArgument($argument); $definition->replaceArgument($index, $argument); $definition->setArguments($arguments);
$definition->getMethodCalls(); $definition->addMethodCall($method, $arguments); $definition->setMethodCalls($methodCalls);
SYMFONY CAFÉ KYIV
MANAGING CONFIGURATION WITH EXTENSIONS
• Let’s take a look at the code.
WWW.GROSSUM.COM SYMFONY CAFÉ KYIV
CONTROLLING THE PASS ORDERING
• PassConfig::TYPE_BEFORE_OPTIMIZATION • PassConfig::TYPE_OPTIMIZE • PassConfig::TYPE_BEFORE_REMOVING • PassConfig::TYPE_REMOVE • PassConfig::TYPE_AFTER_REMOVING
WWW.GROSSUM.COM SYMFONY CAFÉ KYIV
USING A FACTORY TO CREATE SERVICES
• Passing Arguments to the Factory Method
WWW.GROSSUM.COM SYMFONY CAFÉ KYIV
ADVANCED CONTAINER CONFIGURATION
• Marking Services as public / private
• Aliasing
WWW.GROSSUM.COM SYMFONY CAFÉ KYIV
ADVANCED CONTAINER CONFIGURATION
• Requiring Files
• Decorating Services
WWW.GROSSUM.COM SYMFONY CAFÉ KYIV
THANKS! DENIS MALAVSKY Company: Grossum Phone: +38 (063) 478-2449 E-mail: [email protected] Skype: malavskuy
WWW.GROSSUM.COM SYMFONY CAFÉ KYIV