日期:2014-05-17 浏览次数:20444 次
<?php
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();
}
?>
<?php
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)
{
&n