时间:2021-07-01 10:21:17 帮助过:5人阅读
abstract class BaseItem
{
/**
* @param array $fields
*/
public function __construct(array $fields)
{
$this->buildFromArray($fields);
}
/**
* @param array $fields
*/
abstract public function buildFromArray(array $fields);
/**
* @return array
*/
abstract public function convertToArray();
}
?>
include_once 'BaseItem.php';
class Listing extends BaseItem
{
protected $title;
protected $manufacturer;
protected $currency;
protected $price;
/**
* @inheritDoc
*/
public function convertToArray()
{
return array(
'title' => $this->title,
'manufacturer' => $this->manufacturer,
'currency' => $this->currency,
'price' => $this->price,
);
}
/**
* @inheritDoc
*/
public function buildFromArray(array $fields)
{
$this->title = $fields['title'];
$this->manufacturer = $fields['manufacturer'];