oxidprojects / dependency-injection
OXID eShop 缺少的依赖注入
0.1.4
2023-02-23 11:24 UTC
Requires
Requires (Dev)
- mikey179/vfsstream: ^1.6
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^6
- symfony/config: *
- symfony/yaml: *
This package is auto-updated.
Last update: 2024-09-23 14:44:23 UTC
README
OXID eShop 缺少的依赖注入
安装
composer require "oxidprojects/dependency-injection"
如何使用
-
在模块中创建
services.yaml
文件:(例如source/modules/tm/Sunshine/services.yaml
)services: tm\ModuleOutput: class: 'tm\ModuleOutput'
-
project_container()
是一个全局函数。<?php class Controller extends FrontendController { public function render() { $output = project_container()->get(ModuleOutput::class); $this->addTplParam('title', $output->html('Hello dependency injection')); return 'template'; } }
网站链接
- 您拥有所有 Symfony 服务容器 的功能。
- 查看可用于 注入类 的其他方法。您不应每次都使用
__construct()
方法。