/** * modify item (submit) * * called on item update from (@see collection::modify) * * @return array data */ function modify($data) { $this->modify_before(reference::make($data)); $_data = $data; $this->format_fields($data, 'modify'); unset($data[$this->get_key()]); // $this->filter_data($data); $keys = $this->get_fields_keys(); foreach ($keys as $key) { if (isset($data[$key]) && $this->in_working_set($key)) { $this->data[$key] = $data[$key]; } } // restore key $_data[$this->get_key()] = $data[$this->get_key()] = $this->data[$this->get_key()] = $this->get_id(); core::dprint('modify ' . get_class($this) . ' #id ' . $data[$this->get_key()]); // save to db $this->save(); // working fields set deny modifying extra data, // only with full update if (empty($this->working_fields)) { $this->modify_after($_data); } else { $this->modify_partial_after($_data, $this->working_fields); } // remove renderer and other cache $this->drop_internal_cache(); // call onload $data = $this->get_data(); $this->filter_data($data); $this->set_data($data); return $data; }
<?php require '../loader.php'; $reftest = new referenceTest(); $dataA = ['param' => 1]; $dataO = new stdClass(['param' => 1]); $reftest->testA(reference::make($dataA)); test_assert($dataA['param'] === 'helloA'); $reftest->testO(reference::make($dataO)); test_assert($dataO->param === 'helloO'); test_except('tf_exception', function () use($reftest, $dataO) { $reftest->testA(reference::make($dataO)); }); class referenceRunner { function testA($data) { $data['param'] = 'helloA'; } function testO($data) { $data->param = 'helloO'; } } class referenceTest { protected $rr; function __construct() { $this->rr = new referenceRunner(); }