diff --git a/src/foreignField/ForeignFieldModel.php b/src/foreignField/ForeignFieldModel.php index 1ccf028..b273ba2 100644 --- a/src/foreignField/ForeignFieldModel.php +++ b/src/foreignField/ForeignFieldModel.php @@ -9,13 +9,12 @@ use Exception; use lenz\craft\utils\helpers\ArrayHelper; use lenz\craft\utils\helpers\ElementHelpers; -use Serializable; use yii\base\InvalidConfigException; /** * Class ForeignModel */ -abstract class ForeignFieldModel extends Model implements Serializable +abstract class ForeignFieldModel extends Model { /** * @var ForeignField @@ -98,22 +97,6 @@ public function isEmpty(): bool { return false; } - /** - * @inheritDoc - */ - public function serialize(): string { - return serialize($this->getSerializedData()); - } - - /** - * @inheritDoc - * @throws Exception - */ - public function unserialize(string $data) { - $data = unserialize($data); - $this->setSerializedData(is_array($data) ? $data : []); - } - /** * @param ElementInterface|null $owner * @return $this @@ -130,14 +113,10 @@ public function withOwner(ElementInterface $owner = null): static { return $model; } - - // Protected methods - // ----------------- - /** * @return array */ - protected function getSerializedData() : array { + public function __serialize() : array { return [ '_attributes' => $this->attributes, '_field' => $this->_field->handle, @@ -149,11 +128,12 @@ protected function getSerializedData() : array { * @param array $data * @throws Exception */ - protected function setSerializedData(array $data) { + public function __unserialize(array $data): void { $this->_owner = ElementHelpers::unserialize( ArrayHelper::get($data, '_owner') ); + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->_field = Craft::$app->getFields()->getFieldByHandle( (string)ArrayHelper::get($data, '_field', ''), $this->_owner->getFieldContext() ?? null @@ -165,6 +145,10 @@ protected function setSerializedData(array $data) { } } + + // Protected methods + // ----------------- + /** * @param string $message * @return string