承接 jesusslim/pinject 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jesusslim/pinject

Composer 安装命令:

composer require jesusslim/pinject

包简介

inject in php

关键字:

README 文档

README

Inject in PHP !

usage

[English] Chinese

Install

pinject in packagist:https://packagist.org/packages/jesusslim/pinject

Install:

composer require jesusslim/pinject

If your composer not allowed dev-master,add this config

"minimum-stability": "dev"

into your composer.json.

Injector

The InjectorInterface decalare some function for Inject,like

map //map a concrete or class or object or closure to the inject container
get //get things your mapped
produce //produce concrete

The Injector class implements InjectorInterface.Make your own class which needs to use inject extends the Injector class.Then use the functions:

//map a data or object
$injector->mapData('test',12345);
$injector->mapData(Student::class,new Student('Slim'));

//map a class
$injector->mapSingleton(StudentInterface::class,GoodStudent::class);

//produce
//if the key is found in mapped data,objects,it will return the things we mapped.
//if the key is found in mapped classes,it will check if this class is been produced,if it's been produced,it return the concrete that produced before,else return a new concrete of this class.
//if this key not found in any map,it will try to reflect this class unless we use the function mustReg() to make sure all the things can be produced should be mapped first.
$injector->produce(StudentInterface::class);

//call an function
//it will fill the paramters of this function with the concrete produced by pinject.
$injector->call(function(Student $std){
	...
});

//call an function in class
//it will call a function in class.it will try to find the class from pinject if it has been produced or reflect it.and fill the paramters with concrete produced by pinject.
$injector->callInClass($class_name,$action,$out_params);

Chains

We can use Chains to do some chaining operations.

Example:

$chains = new Chains($app);
//here $app is an Injector
$chains->chain(RequestHandler::class)
->chain(function($data,$next){
    $r = Auth::checkToken($data['token']);
    if($r !== true){
        dump("Token wrong");
    }else{
        $next($data);
    }
})
->chain(Student::class)
->chain(function($data){
    dump($data);
})
->action('handle')
->run();
//or use runWith($your_last_chain_func);

We can chain a Closure or a class into the chains.If it's a class,it will call the method named 'handle'.Every Closure or method for handle,should have two paramters:the data passing by in the chains,and the next handler.And at last of each chain,we shoule call the next handler if it's success.

Another way to use chains:

Another way to use chains is that use runWild instead of run/runWith,and it's more like the useage of Martini/Injector in golang.

Example:

$chains = new \Inject\Chains($app);
$app->mapData('any_param_here','Example');
$the_given_params_for_handlers = [
	'seems_wild' => 'OK'
];
$rtn = $chains->chain(function($any_param_here,$seems_wild){
	var_dump($any_param_here.' is '.$seems_wild);
})->chain(function(){
	return "END";
})->data($the_given_params_for_handlers)
->runWild();
var_dump($rtn);

As we see here,the difference between runWild and run/runWith is that,runWild support any kind of handlers,and any handler return anything will break the loop and return the result.

jesusslim/pinject 适用场景与选型建议

jesusslim/pinject 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 710 次下载、GitHub Stars 达 7, 最近一次更新时间为 2016 年 07 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「inject」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jesusslim/pinject 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jesusslim/pinject 我们能提供哪些服务?
定制开发 / 二次开发

基于 jesusslim/pinject 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 710
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 7
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-26