你如何在 Laravel 中实现外部包的接口?比如说,我想使用 Mashape/Unirest API 来分析文本,但将来我想切换到其他 API 提供程序,并且不会对代码进行太多更改。
interface AnalyzerInterface {
public function analyze(); //or send()?
}
class UnirestAnalyzer implements AnalyzerInterface {
function __constructor(Unirest unirest){
//this->...
}
function analyze($text, $lang) {
Unirest::post(.. getConfig() )
}
//some private methods to process data
}
以及在哪里放置这些文件 interfece 和 UnirestAnalyzer?为他们制作特殊文件夹,添加到作曲家?添加命名空间?