. */ namespace SP\DataModel; use SP\Core\Exceptions\NoSuchPropertyException; use SP\Util\Util; /** * Trait Datamodel * * @package SP\DataModel */ trait SerializedModel { /** * @param string|null $class * @param string $property * * @return mixed|null * @throws NoSuchPropertyException */ public function hydrate(string $class = null, string $property = 'data') { if (property_exists($this, $property)) { if ($this->$property === null) { return null; } if ($class !== null) { return Util::unserialize($class, $this->$property); } return unserialize($this->$property); } throw new NoSuchPropertyException($property); } }