* @copyright Meritoo.pl */ abstract class BaseItem { /** * Class constructor * * @param array $data (optional) Data to set in properties of the item */ public function __construct(array $data = []) { $this->setValues($data); } /** * Sets given value in given property * * @param string $property Name of property to set the value * @param mixed $value Value to set in property * @return mixed */ abstract public function setValue($property, $value); /** * Sets values in each property of the item * * @param array $data Data to set in properties of the item * @return $this */ private function setValues(array $data) { /* * Oops, no data */ if (empty($data)) { return $this; } /* * Let's iterate through each property */ foreach ($data as $property => $value) { $this->setValue($property, $value); } return $this; } }