PHP 클래스 dbObject, PHP-MySQLi-Database-Class

파일 보기 프로젝트 열기: joshcam/PHP-MySQLi-Database-Class 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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

보호된 프로퍼티들

프로퍼티 타입 설명
$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