Base class for one item - add class constructor & allow to set values directly in the constructor

This commit is contained in:
Meritoo
2017-09-29 20:56:39 +02:00
parent bbd466610c
commit 6159731768
17 changed files with 190 additions and 84 deletions

View File

@@ -16,13 +16,32 @@ namespace Meritoo\LimeSurvey\ApiClient\Base\Result;
*/
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
*/
public function setValues($data)
private function setValues(array $data)
{
/*
* Oops, no data
@@ -40,13 +59,4 @@ abstract class BaseItem
return $this;
}
/**
* 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);
}