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
Показать файл Открыть проект

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

Свойство Тип Описание
$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
public getIterator ( ) : ArrayIterator
Результат ArrayIterator

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