adlogix/zf-symfony-container
Composer 安装命令:
composer require adlogix/zf-symfony-container
包简介
Zend Framework module to leverage the symfony dependency injection container
README 文档
README
Zend Framework module to leverage the symfony dependency injection container
Installation
- Install the module via composer by running:
composer require adlogix/zf-symfony-container:^0.4
- Add the
Adlogix\ZfSymfonyContainermodule to the module section of yourconfig/application.config.php
Configuration
Symfony Container parameters can be defined in the application configurations:
<?php return [ 'zf_symfony_container' => [ // directory where to look for the service container configurations (e.g. config/services.yaml) 'config_dir' => 'config', // Caching options 'cache' => [ // directory where the cached container will be stored 'dir' => 'data/ZfSymfonyContainer', // name of the file to generate the cached container class 'filename' => 'zf_symfony_container_cache', // name of the class of the generated cached container 'classname' => 'CachedContainer', // the namespace of the generated cached container 'namespace' => 'Adlogix\ZfSymfonyContainer\DependencyInjection', // enable in dev mode 'debug' => false ], ], ];
Usage
Refer to the documentation of the Symfony DI Component for information on how to use the DI container.
Obtain a symfony defined service
Any existing symfony service will directly be available through the Service Manager of Zend:
<?php $service = $this->getServiceLocator()->get(\My\Public\Service::class);
Build a symfony defined service with a Zend service dependency
It will happen that you have to use a dependency which is already loaded into the Zend Service Manager. For example, if you are using the Doctrine Module and you need to have the instance of the Entity Manager, you can leverage the ZendServiceProxyFactory class:
services: _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. public: false # Allows optimizing the container by removing unused services; this also means # fetching services directly from the container via $container->get() won't work. # The best practice is to be explicit about your dependencies anyway. # # Define service that needs to be retrieved via the Zend Service Manager # Doctrine\ORM\EntityManagerInterface: factory: ['Adlogix\ZfSymfonyContainer\Service\Factory\ZendServiceProxyFactory', getService] arguments: ['@zend.container', 'doctrine.entitymanager.orm_default'] class: Doctrine\ORM\EntityManagerInterface
With this configuration, and service defined with the symfony container requiring an instance of Doctrine\ORM\EntityManagerInterface will receive this from the Zend Service Manager.
Obtain the symfony container instance
<?php $container = $this->getServiceLocator()->get('zf_symfony_container');
Use the Zend config as Symfony parameters
The module takes care of transforming all zend configurations into Symfony parameters allowing you to immediately use the parameters in the service definition file:
<?php // global.php return [ 'myconfig' => 'hello world' ];
services: Some\Service: arguments: ['%myconfig%']
When the Zend configuration contains deep level keys, the "keys" will be concatenated with a dot.
<?php // global.php return [ 'deep' => [ 'level' => [ 'config' => 'hello world' ] ] ];
services: Some\Service: arguments: ['%deep.level.config%']
Note: zend configurations using callables will be ignored and cannot be used!
adlogix/zf-symfony-container 适用场景与选型建议
adlogix/zf-symfony-container 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.84k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dependency injection」 「container」 「symfony」 「zf2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adlogix/zf-symfony-container 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adlogix/zf-symfony-container 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adlogix/zf-symfony-container 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A fast and intuitive dependency injection container.
Dependency injection container for the Monolith framework.
The PSR-11 container bridges
Http Microframework for Hack
PHP Dependency Injection Container
统计信息
- 总下载量: 3.84k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-19