File src/BigOrm.php

class Tlf\BigOrm

Minimal ORM implementation.

Declare $protected ClassName $_article; and public int $article_id; to automagically make $obj->article load the related article as a BigOrm object.

Constants

Properties

  • public string $table;
  • protected BigDb $db;

Methods

  • public function __construct(BigDb $db) Create a BigOrm instance.

  • public function get_db_row(): array Get a db-representation of your item. This is intended to convert your Orm object into a mysql-storeable array. It is NOT intended to load from the database.

  • public function set_from_db(array $row) Initialize the Orm object from a database row

  • public function bin_to_uuid(string $uuid): string Convert binary uuid to a string uuid (mysql compatible).

  • public function uuid_to_bin(string $uuid): string Convert a string uuid to a binary uuid (mysql compatible).

  • public function str_to_datetime(string $mysql_datetime): \DateTime Convert a mysql-stored datetime string to a PHP DateTime instance

  • public function datetime_to_str(\DateTime $datetime): string Convert a PHP DateTime object into a mysql DATETIME string

  • public function __get(string $prop): mixed Call and return the property getter. For $prop = 'author', call $this->getAuthor()

  • public function __set(string $prop, mixed $value) Call the property setter. For $prop = 'author', call $this->setAuthor($value)

  • public function save(): int Store the item in the database. If is_saved() returns true, then use an UPDATE, else use an INSERT.
    UPDATEs are performed based on the int $id property of the Orm object, assuming an id int PRIMARY KEY AUTO_INCREMENT db column.

  • public function delete(): bool Delete this item from the database, where the db column id matches this item's property id

  • public function refresh(): array Refreshes this item, so it matches what's in the database. Just queries for this item's row (by id), then calls $this->set_from_db($row).

  • public function is_saved(): bool Check if the current item is already stored in the database. Default implementation returns true if id property isset & is > 0

  • public function table(): string Get the table name. Default implementation return $this->table or the lowercase version of the class name if $this->table is null