PHP如何实现职责链设计模式


这篇文章主要介绍“PHP如何实现职责链设计模式”,在日常操作中,相信很多人在PHP如何实现职责链设计模式问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”PHP如何实现职责链设计模式”的疑惑有所帮助!接下来,请跟着小编一起来学习吧! 文件结构:IndexController 为调用端,UserInfoEntity 用户实体用于存用户信息,flow 里面的为各种处理流程IndexController

setName('zhangsan');
$startHandler->setNextHandler(newReception())
->setNextHandler(newClinic())
->setNextHandler(newCashier())
->setNextHandler(newPharmacy(免费云主机域名));
$startHandler->execute($userInfo);
}
}

UserInfoEntity

name;
}
publicfunctionsetName(string$name):UserInfoEntity
{
$this->name=$name;
return$this;
}
publicfunctionisRegistrationDone():bool
{
return$this->registrationDone;
}
publicfunctionsetRegistrationDone(bool$registrationDone):UserInfoEntity
{
$this->registrationDone=$registrationDone;
return$this;
}
publicfunctionisDoctorCheckUpDone():bool
{
return$this->doctorCheckUpDone;
}
publicfunctionsetDoctorCheckUpDone(bool$doctorCheckUpDone):UserInfoEntity
{
$this->doctorCheckUpDone=$doctorCheckUpDone;
return$this;
}
publicfunctionisMedicineDone():bool
{
return$this->medicineDone;
}
publicfunctionsetMedicineDone(bool$medicineDone):UserInfoEntity
{
$this->medicineDone=$medicineDone;
return$this;
}
publicfunctionisPaymentDone():bool
{
return$this->paymentDone;
}
publicfunctionsetPaymentDone(bool$paymentDone):UserInfoEntity
{
$this->paymentDone=$paymentDone;
return$this;
}
}

HandlerInterface


AbstractHandler

nextHandler=$handler;
return$this->nextHandler;
}
publicfunctionexecute(UserInfoEntity$info)
{
if(!empty($this->nextHandler)){
try{
$this->nextHandler->do($info);
}catch(Exception$e){
return;
}
return$this->nextHandler->execute($info);
}
}
publicfunctiondo(UserInfoEntity$info)
{
//TODO:Implementdo()method.
}
}

StartHandler


Cashier

setPaymentDone(true);
}
}

Clinic

setDoctorCheckUpDone(true);
}
}

Pharmacy

setMedicineDone(true);
}
}

Reception

setRegistrationDone(true);
}
}

写一个单元测试跑一下 indexController 的 index 方法,结果如下:到此,关于“PHP如何实现职责链设计模式”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注百云主机网站,小编会继续努力为大家带来更多实用的文章!

相关推荐: java.lang.NoClassDefFoundError: org/jaxen/JaxenException报错怎么解决

本篇内容介绍了“java.lang.NoClassDefFoundError: org/jaxen/JaxenException报错怎么解决”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 03/03 21:24
下一篇 03/03 21:24

相关推荐