【发布时间】:2018-08-09 02:28:19
【问题描述】:
我希望能够使用如下所示的对象来检索新订单和新发票。我觉得它的可读性最强,但我在编写 PHP 类以这种方式工作时遇到了麻烦。
$amazon = new Amazon();
$amazon->orders('New')->get();
$amazon->invoices('New')->get();
在我的 PHP 类中,我的 get() 方法如何区分是退货还是退货?
<?php
namespace App\Vendors;
class Amazon
{
private $api_key;
public $orders;
public $invoices;
public function __construct()
{
$this->api_key = config('api.key.amazon');
}
public function orders($status = null)
{
$this->orders = 'orders123';
return $this;
}
public function invoices($status = null)
{
$this->invoices = 'invoices123';
return $this;
}
public function get()
{
// what is the best way to return order or invoice property
// when method is chained?
}
}
【问题讨论】:
-
你能在这里展示你想要实现的类吗?
-
@PubuduJayawardana 添加了
标签: php api class methods chaining