[英]PHP: chaining methods with variable methods
這是我的代碼:
return PDF::loadFile($url)
->setPaper('a4')
->setOption('margin-top', 10)
->stream('somefile.pdf');
當我在多個位置調用此方法時,是否存在某種以這種方式調用它的選項?
return PDF::loadFile($url)
->callSettings()
->stream('somefile.pdf');
設置為->setPaper('a4')->setOption('margin-top', 10)
。
這很容易。 只需在PDF
類中實現一個新的callSettings()
方法,即可調用這些方法並返回$this
:
public function callSettings()
{
$this->setPaper('a4')
->setOption('margin-top', 10);
return $this;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.