veasin / nx-container
Container for nx
Installs: 23
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:framework
Requires
- php: >=8.2
- psr/container: *
This package is auto-updated.
Last update: 2024-11-03 07:38:13 UTC
README
container for nx
Installation
composer require urn2/nx-container
Usage
use nx\Container; $container =new Container(); $container['int']=123; $container['string']='123'; $container['instance']=fn()=>new \Radis();//获取时构建 shared 只在获取时候构建一次 否则每次 $container['obj']=$this; //service方法 每次返回都不同 $container['some.service'] =$container->service(fn()=>new "Some Factory Function"(), shared:false); //method方法 可多次执行 $container['some.method'] =$container->method(fn($s)=>echo $s); $container['some.method']('123'); //set方法 $container['parameter'] =$container->set([ //'type'=>'value', 'value'=>123, 'shared'=>true, ]); $container['service'] =$container->set([ //'type'=>'service', 'class'=>$container->ref('key'),//'%key%',//应支持一次读取 或 转换成对象(函数) 'args'=>[1,2,3], 'shared'=>false, ]); $container['method'] =$container->set([ //'type'=>'method', 'method'=>fn($s)=>echo $s, 'shared'=>true, ]);