The missing dependency injection for OXID eShop
composer require "oxidprojects/dependency-injection"
-
Create
services.yaml
in a module: (eg.source/modules/tm/Sunshine/services.yaml
)services: tm\ModuleOutput: class: 'tm\ModuleOutput'
-
project_container()
is a global function.<?php class Controller extends FrontendController { public function render() { $output = project_container()->get(ModuleOutput::class); $this->addTplParam('title', $output->html('Hello dependency injection')); return 'template'; } }
- You have all the Power of Symfony Service Container.
- See which other methods are available to inject classes. You must not use every time the
__construct()
method.