File src/BigOrm.php
class Tlf\BigOrm
Extend this class to represent a single row from your database. Provides many convenience features like saving, hooks, and coercing values between the database version & application version
See source code at /src/BigOrm.php
Constants
Properties
-
static protected $__reflection_types__ = [];Used to track types of properties for database coersion purposes -
public string $table; -
protected BigDb $db;
Methods
-
public function __construct(BigDb $db)Create a BigOrm instance. -
public function get_db_row(): arrayGet 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. -
protected function row_to_props(array $db_row, ...$props_to_coerce): voidSet each key/value pair to the same-named properties on this class -
protected function props_to_row(array $raw_props, array $coerce_props): arrayGet a database-friendly row from an array of property values -
public function get_prop_value(string $prop_name, mixed $db_value): mixedGet the database value from a property -
public function get_db_value(string $prop_name): mixedGet the database value from a property. -
public function set_from_db(array $row)Initialize the Orm object from a database row -
public function props_to_array(...$properties): arrayGet an array of this object's properties.
Your subclass may call this from get_db_row()
-
public function set_props_from_array(array $row, ...$properties): voidSet properties from an array. Your subclass may call this fromset_from_db() -
public function bin_to_uuid(string $uuid): stringConvert binary uuid to a string uuid (mysql compatible). -
public function uuid_to_bin(string $uuid): stringConvert a string uuid to a binary uuid (mysql compatible). -
public function generate_uuid(): stringGenerate a (hopefully) mysql-compatible UUID string. Method not thoroughly tested for mysql compatability. -
public function str_to_datetime(string $mysql_datetime): \DateTimeConvert a mysql-stored datetime string to a PHP DateTime instance -
public function datetime_to_str(\DateTime $datetime): stringConvert a PHP DateTime object into a mysql DATETIME string -
public function __get(string $prop): mixedCall 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(): intStore the item in the database. Ifis_saved()returnstrue, then use an UPDATE, else use an INSERT.
UPDATEs are performed based on theint $idproperty of the Orm object, assuming anid int PRIMARY KEY AUTO_INCREMENTdb column. -
public function delete(): boolDelete this item from the database, where the db columnidmatches this item's propertyid -
public function refresh(): arrayRefreshes 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(): boolCheck if the current item is already stored in the database. Default implementation returns true ifidproperty isset & is > 0 -
public function table(): stringGet the table name. Default implementation return$this->tableor the lowercase version of the class name if$this->tableis null