public function bind($taintedData)
{
if ($taintedData === null) {
$taintedData = array();
}
if (!is_array($taintedData)) {
throw new UnexpectedTypeException('You must pass an array parameter to the bind() method');
}
foreach ($this->fields as $key => $field) {
if (!isset($taintedData[$key])) {
$taintedData[$key] = null;
}
}
$taintedData = $this->preprocessData($taintedData);
foreach ($taintedData as $key => $value) {
if ($this->has($key)) {
$this->fields[$key]->bind($value);
}
}
$data = $this->getTransformedData();
$iterator = new RecursiveFieldsWithPropertyPathIterator($this);
$iterator = new \RecursiveIteratorIterator($iterator);
foreach ($iterator as $field) {
$field->updateObject($data);
}
// bind and reverse transform the data
parent::bind($data);
$this->extraFields = array();
foreach ($taintedData as $key => $value) {
if (!$this->has($key)) {
$this->extraFields[] = $key;
}
}
}