Skip to content
This repository was archived by the owner on Sep 27, 2021. It is now read-only.
This repository was archived by the owner on Sep 27, 2021. It is now read-only.

Serialize into object #8

@qurben

Description

@qurben

Add the option to save a simple PHP object into the database. For instance creating a simple Email object which can only contain a valid email address.

Such class would look something like the following:

class Email extends PersistenceObject {
  /** @var string **/
  protected $email;

  /**
   * @param string $email;
   */
  public function __construct($email) {
    $this->assertValidEmail($email);
    $this->email = $email;
  }
  
  public function getValue() {
    return $this->email;
  }
}

abstract class PersistenceObject {
  abstract public function __construct($value);
  abstract public function getValue();
}

The objects should require one required constructor argument and implement the getValue method.

When defining a model the definition would look something like:

protected static $persistent_attributes = [
  'email' => [T::Object, true, Email::class],
];

Or just, where the orm checks if the type is instantiable (subclass of PersistenceObject)

protected static $persistent_attributes = [
  'email' => [Email::class],
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions