Skip to content

Commit

Permalink
Remove deprecated Serializable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-lenz committed Feb 20, 2023
1 parent 42071b9 commit 7de47ae
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions src/foreignField/ForeignFieldModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -165,6 +145,10 @@ protected function setSerializedData(array $data) {
}
}


// Protected methods
// -----------------

/**
* @param string $message
* @return string
Expand Down

0 comments on commit 7de47ae

Please sign in to comment.