PHP 클래스 Lazer\Classes\Core_Database

There are classes to use JSON files like file database. Using style was inspired by ORM classes.
저자: Grzegorz Kuźnik
상속: implements IteratorAggregate, implements Countable
파일 보기 프로젝트 열기: greg0/lazer-database

보호된 프로퍼티들

프로퍼티 타입 설명
$currentId ID of current row if setted
$currentKey Key if current row if setted
$data Contain returned data from file as object or array of objects
$name Name of file (table)
$pending array Pending functions with values
$resetKeys integer Information about to reset keys in array or not to
$set Object with setted data

공개 메소드들

메소드 설명
__get ( string $name ) : mixed Returning variable from Object
__isset ( string $name ) : boolean Check if the given field exists
__set ( string $name, mixed $value ) Validating fields and setting variables to current operations
addFields ( array $fields ) Add new fields to table, array schema like in create() function
andWhere ( string $field, string $op, mixed $value ) : Core_Database Alias for where()
asArray ( string $key = null, string $value = null ) : array Returning data as indexed or assoc array.
config ( ) : object Returning object with config for table
count ( ) : mixed Return count in integer or array of integers (if grouped)
create ( string $name, array $fields ) Creating new table
debug ( ) Debug functions, prints whole query with values
delete ( ) : boolean Deleting loaded data
deleteFields ( array $fields ) Delete fields from array
fields ( ) : array Return array with names of fields
find ( integer $id = NULL ) : Core_Database Returns one row with specified ID
findAll ( ) Make data ready to read
getIterator ( ) : ArrayIterator Iterator for Data
groupBy ( string $column ) : Core_Database Grouping results by one field
lastId ( ) : integer Returning last ID from table
limit ( integer $number, integer $offset ) : Core_Database Limit returned data
name ( ) : string Returns table name
orWhere ( string $field, string $op, mixed $value ) : Core_Database Alias for where(), setting OR for searching
orderBy ( string $key, string $direction = 'ASC' ) : Core_Database Sorting data by field
relations ( string | null $tableName = null ) : array Returning assoc array with relationed tables
remove ( string $name ) : boolean | Lazer\Classes\LazerException Removing table with config
save ( ) Saving inserted or updated data
schema ( ) : array Returning assoc array with types of fields
table ( string $name ) : Lazer\Classes\Database Factory pattern
where ( string $field, string $op, mixed $value ) : Core_Database Where function, like SQL
with ( string $table ) : Core_Database JOIN other tables

보호된 메소드들

메소드 설명
clearKeyInfo ( ) Set NULL for currentId and currentKey
clearQuery ( ) Clear info about previous queries
getData ( ) : array Get rows from table
getRowKey ( integer $id ) : integer Returns array key of row with specified ID
groupByPending ( ) Grouping array pending method
limitPending ( ) Pending function for limit()
orderByPending ( ) Sort an array of objects by more than one field.
pending ( ) Execute pending functions
setData ( ) Setting data to Database::$data
setFields ( ) Setting fields with default values
setPending ( ) Set pending functions in right order with default values (Empty).
wherePending ( ) : boolean Filter function for array_filter() in where()
withPending ( ) Pending function for with(), joining other tables to current

메소드 상세

__get() 공개 메소드

Returning variable from Object
public __get ( string $name ) : mixed
$name string Field name
리턴 mixed Field value

__isset() 공개 메소드

Check if the given field exists
public __isset ( string $name ) : boolean
$name string Field name
리턴 boolean True if the field exists, false otherwise

__set() 공개 메소드

Validating fields and setting variables to current operations
public __set ( string $name, mixed $value )
$name string Field name
$value mixed Field value

addFields() 공개 메소드

Add new fields to table, array schema like in create() function
public addFields ( array $fields )
$fields array Associative array

andWhere() 공개 메소드

Alias for where()
public andWhere ( string $field, string $op, mixed $value ) : Core_Database
$field string Field name
$op string Operator
$value mixed Field value
리턴 Core_Database

asArray() 공개 메소드

Returning data as indexed or assoc array.
public asArray ( string $key = null, string $value = null ) : array
$key string Field that will be the key, NULL for Indexed
$value string Field that will be the value
리턴 array

clearKeyInfo() 보호된 메소드

Set NULL for currentId and currentKey
protected clearKeyInfo ( )

clearQuery() 보호된 메소드

Clear info about previous queries
protected clearQuery ( )

config() 공개 메소드

Returning object with config for table
public config ( ) : object
리턴 object Config

count() 공개 메소드

Return count in integer or array of integers (if grouped)
public count ( ) : mixed
리턴 mixed

create() 공개 정적인 메소드

For example few fields: Database::create('news', array( 'title' => 'string', 'content' => 'string', 'rating' => 'double', 'author' => 'integer' )); Types of field: - boolean - integer - string - double (also for float type) ID field isn't required (it will be created automatically) but you can specify it at first place.
public static create ( string $name, array $fields )
$name string Table name
$fields array Field configuration

debug() 공개 메소드

Debug functions, prints whole query with values
public debug ( )

delete() 공개 메소드

Deleting loaded data
public delete ( ) : boolean
리턴 boolean

deleteFields() 공개 메소드

Delete fields from array
public deleteFields ( array $fields )
$fields array Indexed array

fields() 공개 메소드

Return array with names of fields
public fields ( ) : array
리턴 array Fields

find() 공개 메소드

Returns one row with specified ID
public find ( integer $id = NULL ) : Core_Database
$id integer Row ID
리턴 Core_Database

findAll() 공개 메소드

Make data ready to read
public findAll ( )

getData() 보호된 메소드

Get rows from table
protected getData ( ) : array
리턴 array

getIterator() 공개 메소드

Iterator for Data

getRowKey() 보호된 메소드

Returns array key of row with specified ID
protected getRowKey ( integer $id ) : integer
$id integer Row ID
리턴 integer Row key

groupBy() 공개 메소드

Grouping results by one field
public groupBy ( string $column ) : Core_Database
$column string
리턴 Core_Database

groupByPending() 보호된 메소드

Grouping array pending method
protected groupByPending ( )

lastId() 공개 메소드

Returning last ID from table
public lastId ( ) : integer
리턴 integer Last ID

limit() 공개 메소드

Should be used at the end of chain, before end method
public limit ( integer $number, integer $offset ) : Core_Database
$number integer Limit number
$offset integer Offset number
리턴 Core_Database

limitPending() 보호된 메소드

Pending function for limit()
protected limitPending ( )

name() 공개 메소드

Returns table name
public name ( ) : string
리턴 string table name

orWhere() 공개 메소드

Alias for where(), setting OR for searching
public orWhere ( string $field, string $op, mixed $value ) : Core_Database
$field string Field name
$op string Operator
$value mixed Field value
리턴 Core_Database

orderBy() 공개 메소드

Sorting data by field
public orderBy ( string $key, string $direction = 'ASC' ) : Core_Database
$key string Field name
$direction string ASC|DESC
리턴 Core_Database

orderByPending() 보호된 메소드

@
protected orderByPending ( )

pending() 보호된 메소드

Execute pending functions
protected pending ( )

relations() 공개 메소드

Returning assoc array with relationed tables
public relations ( string | null $tableName = null ) : array
$tableName string | null
리턴 array Fields type

remove() 공개 정적인 메소드

Removing table with config
public static remove ( string $name ) : boolean | Lazer\Classes\LazerException
$name string Table name
리턴 boolean | Lazer\Classes\LazerException

save() 공개 메소드

Saving inserted or updated data
public save ( )

schema() 공개 메소드

Returning assoc array with types of fields
public schema ( ) : array
리턴 array Fields type

setData() 보호된 메소드

Setting data to Database::$data
protected setData ( )

setFields() 보호된 메소드

Setting fields with default values
protected setFields ( )

setPending() 보호된 메소드

Set pending functions in right order with default values (Empty).
protected setPending ( )

table() 공개 정적인 메소드

Factory pattern
public static table ( string $name ) : Lazer\Classes\Database
$name string Name of table
리턴 Lazer\Classes\Database

where() 공개 메소드

Operators: - Standard operators (=, !=, >, <, >=, <=) - IN (only for array value) - NOT IN (only for array value)
public where ( string $field, string $op, mixed $value ) : Core_Database
$field string Field name
$op string Operator
$value mixed Field value
리턴 Core_Database

wherePending() 보호된 메소드

Filter function for array_filter() in where()
protected wherePending ( ) : boolean
리턴 boolean

with() 공개 메소드

JOIN other tables
public with ( string $table ) : Core_Database
$table string relations separated by :
리턴 Core_Database

withPending() 보호된 메소드

Pending function for with(), joining other tables to current
protected withPending ( )

프로퍼티 상세

$currentId 보호되어 있는 프로퍼티

ID of current row if setted
protected $currentId

$currentKey 보호되어 있는 프로퍼티

Key if current row if setted
protected $currentKey

$data 보호되어 있는 프로퍼티

Contain returned data from file as object or array of objects
protected $data

$name 보호되어 있는 프로퍼티

Name of file (table)
protected $name

$pending 보호되어 있는 프로퍼티

Pending functions with values
또한 보기: Lazer\Classes\Core_Database::setPending()
protected array $pending
리턴 array

$resetKeys 보호되어 있는 프로퍼티

Information about to reset keys in array or not to
protected int $resetKeys
리턴 integer

$set 보호되어 있는 프로퍼티

Object with setted data
protected $set