PHP Class Lazer\Classes\Core_Database

There are classes to use JSON files like file database. Using style was inspired by ORM classes.
Author: Grzegorz Kuźnik
Inheritance: implements IteratorAggregate, implements Countable
Afficher le fichier Open project: greg0/lazer-database

Protected Properties

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

Méthodes publiques

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

Méthodes protégées

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

Method Details

__get() public méthode

Returning variable from Object
public __get ( string $name ) : mixed
$name string Field name
Résultat mixed Field value

__isset() public méthode

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

__set() public méthode

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

addFields() public méthode

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

andWhere() public méthode

Alias for where()
public andWhere ( string $field, string $op, mixed $value ) : Core_Database
$field string Field name
$op string Operator
$value mixed Field value
Résultat Core_Database

asArray() public méthode

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

clearKeyInfo() protected méthode

Set NULL for currentId and currentKey
protected clearKeyInfo ( )

clearQuery() protected méthode

Clear info about previous queries
protected clearQuery ( )

config() public méthode

Returning object with config for table
public config ( ) : object
Résultat object Config

count() public méthode

Return count in integer or array of integers (if grouped)
public count ( ) : mixed
Résultat mixed

create() public static méthode

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() public méthode

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

delete() public méthode

Deleting loaded data
public delete ( ) : boolean
Résultat boolean

deleteFields() public méthode

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

fields() public méthode

Return array with names of fields
public fields ( ) : array
Résultat array Fields

find() public méthode

Returns one row with specified ID
public find ( integer $id = NULL ) : Core_Database
$id integer Row ID
Résultat Core_Database

findAll() public méthode

Make data ready to read
public findAll ( )

getData() protected méthode

Get rows from table
protected getData ( ) : array
Résultat array

getIterator() public méthode

Iterator for Data
public getIterator ( ) : ArrayIterator
Résultat ArrayIterator

getRowKey() protected méthode

Returns array key of row with specified ID
protected getRowKey ( integer $id ) : integer
$id integer Row ID
Résultat integer Row key

groupBy() public méthode

Grouping results by one field
public groupBy ( string $column ) : Core_Database
$column string
Résultat Core_Database

groupByPending() protected méthode

Grouping array pending method
protected groupByPending ( )

lastId() public méthode

Returning last ID from table
public lastId ( ) : integer
Résultat integer Last ID

limit() public méthode

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

limitPending() protected méthode

Pending function for limit()
protected limitPending ( )

name() public méthode

Returns table name
public name ( ) : string
Résultat string table name

orWhere() public méthode

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

orderBy() public méthode

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

orderByPending() protected méthode

@
protected orderByPending ( )

pending() protected méthode

Execute pending functions
protected pending ( )

relations() public méthode

Returning assoc array with relationed tables
public relations ( string | null $tableName = null ) : array
$tableName string | null
Résultat array Fields type

remove() public static méthode

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

save() public méthode

Saving inserted or updated data
public save ( )

schema() public méthode

Returning assoc array with types of fields
public schema ( ) : array
Résultat array Fields type

setData() protected méthode

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

setFields() protected méthode

Setting fields with default values
protected setFields ( )

setPending() protected méthode

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

table() public static méthode

Factory pattern
public static table ( string $name ) : Lazer\Classes\Database
$name string Name of table
Résultat Lazer\Classes\Database

where() public méthode

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

wherePending() protected méthode

Filter function for array_filter() in where()
protected wherePending ( ) : boolean
Résultat boolean

with() public méthode

JOIN other tables
public with ( string $table ) : Core_Database
$table string relations separated by :
Résultat Core_Database

withPending() protected méthode

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

Property Details

$currentId protected_oe property

ID of current row if setted
protected $currentId

$currentKey protected_oe property

Key if current row if setted
protected $currentKey

$data protected_oe property

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

$name protected_oe property

Name of file (table)
protected $name

$pending protected_oe property

Pending functions with values
See also: Lazer\Classes\Core_Database::setPending()
protected array $pending
Résultat array

$resetKeys protected_oe property

Information about to reset keys in array or not to
protected int $resetKeys
Résultat integer

$set protected_oe property

Object with setted data
protected $set