Basic CRUD class implementing insert (create), read, update and delete methods.
Classes that derive from \PHPFUI\ORM\Record must define the static members
There is only one record associated with a single CRUD object.
Members of the class can be accessed by their database table field name, case sensitive. On setting a member, it will be cast to the correct PHP type for the field.
- Extends
- Children
- Implements
ArrayAccess
Constants |
public PHPFUI |
public PHPFUI |
public PHPFUI |
public PHPFUI |
public PHPFUI |
Methods |
public __construct(PHPFUI Construct a CRUD object Reads from the database based on the parameters passed to the constructor. No parameters creates an empty object. Possible $parameter types and values
|
public __get(string $field) : ?mixed Allows for $object->field syntax Unset fields will return null |
public __isset(string $field) : bool Allows for empty($object->field) to work correctly |
public __set(string $field, ?mixed $value) : void |
public static addDisplayTransform(string $field, callable $callback) : void Add a transform for get. Callback is passed value. |
public addSetTransform(string $field, callable $callback) : static Add a transform for set. Callback is passed value. |
public blankDate(?string $date) : string |
public clean() : static clean is called before insert or update. Override to impliment cleaning on a specific record |
public create() : int Alias of insert |
public delete() : bool Deletes the record (and children) currently pointed to by the data
|
public displayTransform(string $field, ?mixed $value = NULL) : ?mixed Transform a field for display |
public empty() : bool
|
public getAutoIncrement() : bool
|
public static getFields() : array
|
public getLength(string $field) : int
|
public static getPrimaryKeys() : array
|
public getPrimaryKeyValues() : array
|
public static getTableName() : string
|
public static getVirtualFields() : array Get the virtual field names
|
public insert() : int|bool Inserts current data into table
|
public insertOrIgnore() : int|bool Inserts current data into table or ignores duplicate key if found
|
public insertOrUpdate() : int|bool Inserts current data into table or updates if duplicate key
|
public loaded() : bool
|
public loadFromSQL(string $sql, array $input = []) : bool Load first from SQL query
|
public offsetGet( $offset) : ?mixed Low level get access to underlying data to implement ArrayAccess |
public offsetSet( $offset, $value) : void Low level set access to underlying data to implement ArrayAccess |
public read(array|string|int $fields) : bool Read a record from the db. If more than one match, only the first is loaded.
|
public reload() : bool Reload the object from the database. Unsaved fields are discarded. |
public save() : int|bool Save the record, will either update if it exists or insert if not |
public setCustomValidator(string $className) : static Set a custom validator class |
public setEmpty() : static Sets all fields to default values |
public setFrom(array $values, bool $loaded = false) : static Sets the object to values in the array. Invalid array values are ignored.
|
public update() : bool Update the database with the current record based on table primary key |
public validate(string $optionalMethod = '', ?self $originalRecord = NULL) : array
|
Properties |
protected static bool $autoIncrement = false |
protected static bool $deleteChildren = true |
protected static array $displayTransforms = []
|
protected bool $empty = true |
protected static array $fields = []
|
protected bool $loaded = false |
protected static array $primaryKeys = []
|
protected static array $setTransforms = []
|
protected static string $table = '' |
protected string $validator = '' |
protected static array $virtualFields = []
|
Methods |
protected cleanEmail(string $field) : static Lowercases and strips invalid email characters. Does not validate email address. |
protected cleanFloat(string $field, int $decimalPoints = 2) : static removes all non-digits (0-9, . and -) |
protected cleanLowerCase(string $field) : static Converts the field to all lower case |
protected cleanNumber(string $field) : static removes all non-digits (0-9 and -) from string representation of a number |
protected cleanPhone(string $field, string $regExSeparators = '\-\. ') : static removes all invalid characters. (0-9) and regex separators are valid. |
protected cleanProperName(string $field) : static Properly capitalizes proper names if in single case. Mixed case strings are not altered. |
protected cleanUpperCase(string $field) : static Converts the field to all upper case |
protected timeStamp(?int $timeStamp) : string |
Methods |
private buildWhere(array|string|int $key, array $input) : string Build a where clause
|
private privateInsert(bool $updateOnDuplicate, string $ignore = '') : int|bool Inserts current data into table
|
private validateFieldExists(string $field) : void |
Properties |
protected static bool $autoIncrement = false |
protected static bool $deleteChildren = true |
protected static array $displayTransforms = []
|
protected static array $fields = []
|
protected static array $primaryKeys = []
|
protected static array $setTransforms = []
|
protected static string $table = '' |
protected static array $virtualFields = []
|
Methods |
public static addDisplayTransform(string $field, callable $callback) : void Add a transform for get. Callback is passed value. |
public static getFields() : array
|
public static getPrimaryKeys() : array
|
public static getTableName() : string
|
public static getVirtualFields() : array Get the virtual field names
|