PHP Class dbObject, PHP-MySQLi-Database-Class

Afficher le fichier Open project: joshcam/PHP-MySQLi-Database-Class Class Usage Examples

Méthodes publiques

Свойство Type Description
$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 Properties

Свойство Type Description
$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.

Méthodes publiques

Méthode Description
__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 )

Méthodes protégées

Méthode Description
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()

Private Methods

Méthode Description
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

Method Details

__call() public méthode

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
Résultat mixed

__callStatic() public static méthode

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
Résultat mixed

__construct() public méthode

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

__get() public méthode

Magic getter function
public __get ( $name ) : mixed
$name Variable name
Résultat mixed

__isset() public méthode

public __isset ( $name )

__set() public méthode

Magic setter function
public __set ( $name, $value ) : mixed
Résultat mixed

__toString() public méthode

Converts object data to a JSON string.
public __toString ( ) : string
Résultat string Converted data

__unset() public méthode

public __unset ( $name )

autoload() public static méthode

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

count() protected méthode

Function to get a total records count
protected count ( ) : integer
Résultat integer

delete() public méthode

Delete method. Works only if object primaryKey is defined
public delete ( ) : boolean
Résultat boolean Indicates success. 0 or 1.

get() protected méthode

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
Résultat array Array of dbObjects

getOne() protected méthode

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
Résultat dbObject

insert() public méthode

public insert ( ) : mixed
Résultat mixed insert id or false in case of failure

save() public méthode

Save or Update object
public save ( $data = null ) : mixed
Résultat mixed insert id or false in case of failure

table() public static méthode

Helper function to create a virtual table class
public static table ( $tableName ) : dbObject
Résultat dbObject

toArray() public méthode

Converts object data to an associative array.
public toArray ( ) : array
Résultat array Converted data

toJson() public méthode

Converts object data to a JSON string.
public toJson ( ) : string
Résultat string Converted data

update() public méthode

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

Property Details

$data public_oe property

An array that holds object data
public array $data
Résultat array

$dbTable protected_oe property

Table name for an object. Class name will be used by default
protected stating $dbTable
Résultat stating

$errors public_oe property

An array that holds insert/update/select errors
public array $errors
Résultat array

$isNew public_oe property

Flag to define is object is new or loaded from database
public bool $isNew
Résultat boolean

$modelPath protected_oe static_oe property

Models path
protected static modelPath $modelPath
Résultat modelPath

$pageLimit public_oe static_oe property

Per page limit for pagination
public static int $pageLimit
Résultat integer

$primaryKey protected_oe property

Primary key for an object. 'id' is a default value.
protected stating $primaryKey
Résultat stating

$returnType public_oe property

Return type: 'Array' to return results as array, 'Object' as object 'Json' as json string
public string $returnType
Résultat string

$totalPages public_oe static_oe property

Variable that holds total pages count of last paginate() query
public static int $totalPages
Résultat integer