philetaylor/service-locator-factory
Composer 安装命令:
composer require philetaylor/service-locator-factory
包简介
Get the service locator in anywhere in zf2 statically (bad practice but needed sometimes :-) )
README 文档
README
This is a long term fork of the fezfez/ServiceLocatorFactory as that is no longer maintained...
Allow you to get ServiceManager from everywhere in your application by calling this static factory. Yes its probably very bad practise to do it this way and not use complete DI, however sometimes you just gotta do what you gotta do.
Can be installed with composer - see https://packagist.org/packages/philetaylor/service-locator-factory
<?php
namespace Corp\News;
use Corp\News\NewsDAO;
use Zend\ServiceManager\ServiceManager;
use Corp\ServiceLocator\ServiceLocator;
class NewsDAOFactory
{
private function __construct()
{
}
/**
* @return \Corp\News\NewsDAO
*/
public static function getInstance()
{
$sm = ServiceLocatorFactory::getInstance();
$em = $sm->get('doctrine.entitymanager.orm_default');
return new NewsDAO($em);
}
}
统计信息
- 总下载量: 1.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-01