wikimedia/services
最新稳定版本:4.0.0
Composer 安装命令:
composer require wikimedia/services
包简介
Generic service to manage named services using lazy instantiation based on instantiator callback functions
README 文档
README
Services
A PSR-11-compliant services framework. Services are created by instantiators (callables), which are usually defined in separate wiring files.
Usage
$services = new ServiceContainer(); $services->defineService( 'MyService', static function ( ServiceContainer $services ): MyService { return new MyService(); } ); $services->loadWiringFiles( [ 'path/to/ServiceWiring.php', ] );
Where ServiceWiring.php looks like this:
return [ 'MyOtherService' => static function ( ServiceContainer $services ): MyOtherService { return new MyOtherService( $services->get( 'MyService' ) ); }, // ... ];
Each instantiator receives the service container as the first argument,
from which it may retrieve further services as needed.
Additional arguments for each instantiator may be specified
when constructing the ServiceContainer.
Custom subclasses of ServiceContainer
may offer easier access to certain services:
class MyServiceContainer extends ServiceContainer { public function getMyService(): MyService { return $this->get( 'MyService' ); } public function getMyOtherService(): MyOtherService { return $this->get( 'MyOtherService' ); } } // ServiceWiring.php return [ 'MyOtherService' => static function ( MyServiceContainer $services ): MyOtherService { return new MyOtherService( $services->getMyService() ); }, ];
Running tests
composer install --prefer-dist
composer test
History
This library was first introduced in MediaWiki 1.27 (I3c25c0ac17). It was split out of the MediaWiki codebase and published as an independent library during the MediaWiki 1.33 and MediaWiki 1.34 development cycles.
统计信息
- 总下载量: 443.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2019-06-21