PHP Класс dbObject, PHP-MySQLi-Database-Class

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$data array An array that holds object data
$errors array An array that holds insert/update/select errors
$isNew boolean Flag to define is object is new or loaded from database
$pageLimit integer Per page limit for pagination
$returnType string Return type: 'Array' to return results as array, 'Object' as object 'Json' as json string
$totalPages integer Variable that holds total pages count of last paginate() query

Защищенные свойства (Protected)

Свойство Тип Описание
$dbTable stating Table name for an object. Class name will be used by default
$modelPath modelPath Models path
$primaryKey stating Primary key for an object. 'id' is a default value.

Открытые методы

Метод Описание
__call ( string $method, mixed $arg ) : mixed Catches calls to undefined methods.
__callStatic ( string $method, mixed $arg ) : mixed Catches calls to undefined static methods.
__construct ( array $data = null )
__get ( $name ) : mixed Magic getter function
__isset ( $name )
__set ( $name, $value ) : mixed Magic setter function
__toString ( ) : string Converts object data to a JSON string.
__unset ( $name )
autoload ( $path = null ) * Enable models autoload from a specified path
delete ( ) : boolean Delete method. Works only if object primaryKey is defined
insert ( ) : mixed
save ( $data = null ) : mixed Save or Update object
table ( $tableName ) : dbObject Helper function to create a virtual table class
toArray ( ) : array Converts object data to an associative array.
toJson ( ) : string Converts object data to a JSON string.
update ( array $data = null )

Защищенные методы

Метод Описание
count ( ) : integer Function to get a total records count
get ( integer | array $limit = null, array | string $fields = null ) : array Fetch all objects
getOne ( array | string $fields = null ) : dbObject Convinient function to fetch one object. Mostly will be togeather with where()

Приватные методы

Метод Описание
ArrayBuilder ( ) : dbObject Helper function to create dbObject with Array return type
JsonBuilder ( ) : dbObject Helper function to create dbObject with Json return type
ObjectBuilder ( ) : dbObject Helper function to create dbObject with Object return type.
byId ( $id, array | string $fields = null ) : dbObject | array Get object by primary key.
dbObjectAutoload ( $classname )
join ( string $objectName, string $key = null, string $joinType = 'LEFT', string $primaryKey = null ) : dbObject Function to join object with another object.
paginate ( integer $page, array | string $fields = null ) : array Pagination wraper to get()
prepareData ( )
processAllWith ( array &$data, $shouldReset = true ) Function queries hasMany relations if needed and also converts hasOne object names
processArrays ( array &$data )
processHasOneWith ( ) * Function building hasOne joins for get/getOne method
validate ( array $data )
with ( string $objectName ) : dbObject Function to set witch hasOne or hasMany objects should be loaded togeather with a main object

Описание методов

__call() публичный Метод

Provides magic access to private functions of the class and native public mysqlidb functions
public __call ( string $method, mixed $arg ) : mixed
$method string
$arg mixed
Результат mixed

__callStatic() публичный статический Метод

Transparently creating dbObject class to provide smooth API like name::get() name::orderBy()->get()
public static __callStatic ( string $method, mixed $arg ) : mixed
$method string
$arg mixed
Результат mixed

__construct() публичный Метод

public __construct ( array $data = null )
$data array Data to preload on object creation

__get() публичный Метод

Magic getter function
public __get ( $name ) : mixed
$name Variable name
Результат mixed

__isset() публичный Метод

public __isset ( $name )

__set() публичный Метод

Magic setter function
public __set ( $name, $value ) : mixed
Результат mixed

__toString() публичный Метод

Converts object data to a JSON string.
public __toString ( ) : string
Результат string Converted data

__unset() публичный Метод

public __unset ( $name )

autoload() публичный статический Метод

Calling autoload() without path will set path to dbObjectPath/models/ directory
public static autoload ( $path = null )
$path

count() защищенный Метод

Function to get a total records count
protected count ( ) : integer
Результат integer

delete() публичный Метод

Delete method. Works only if object primaryKey is defined
public delete ( ) : boolean
Результат boolean Indicates success. 0 or 1.

get() защищенный Метод

Fetch all objects
protected get ( integer | array $limit = null, array | string $fields = null ) : array
$limit integer | array Array to define SQL limit in format Array ($count, $offset) or only $count
$fields array | string Array or coma separated list of fields to fetch
Результат array Array of dbObjects

getOne() защищенный Метод

Convinient function to fetch one object. Mostly will be togeather with where()
protected getOne ( array | string $fields = null ) : dbObject
$fields array | string Array or coma separated list of fields to fetch
Результат dbObject

insert() публичный Метод

public insert ( ) : mixed
Результат mixed insert id or false in case of failure

save() публичный Метод

Save or Update object
public save ( $data = null ) : mixed
Результат mixed insert id or false in case of failure

table() публичный статический Метод

Helper function to create a virtual table class
public static table ( $tableName ) : dbObject
Результат dbObject

toArray() публичный Метод

Converts object data to an associative array.
public toArray ( ) : array
Результат array Converted data

toJson() публичный Метод

Converts object data to a JSON string.
public toJson ( ) : string
Результат string Converted data

update() публичный Метод

public update ( array $data = null )
$data array Optional update data to apply to the object

Описание свойств

$data публичное свойство

An array that holds object data
public array $data
Результат array

$dbTable защищенное свойство

Table name for an object. Class name will be used by default
protected stating $dbTable
Результат stating

$errors публичное свойство

An array that holds insert/update/select errors
public array $errors
Результат array

$isNew публичное свойство

Flag to define is object is new or loaded from database
public bool $isNew
Результат boolean

$modelPath защищенное статическое свойство

Models path
protected static modelPath $modelPath
Результат modelPath

$pageLimit публичное статическое свойство

Per page limit for pagination
public static int $pageLimit
Результат integer

$primaryKey защищенное свойство

Primary key for an object. 'id' is a default value.
protected stating $primaryKey
Результат stating

$returnType публичное свойство

Return type: 'Array' to return results as array, 'Object' as object 'Json' as json string
public string $returnType
Результат string

$totalPages публичное статическое свойство

Variable that holds total pages count of last paginate() query
public static int $totalPages
Результат integer