A Mapper that uses MySQL. Cool enne?

This class has no SQL Injection protection so please sanitize the data before you send data to the database.

package Cactus
author Dave Widmer

 Methods

Creates a new mapper. You can optionally pass in the data source adapter.

__construct(Adapter $adapter) 
Inherited

inherited_from \Cactus\Mapper::__construct()

Parameters

$adapter

\Cactus\Adapter

The data adapter.

Get all of the records in the data set.

all(string $column, string $direction) : \Cactus\Collection

Parameters

$column

string

The column to sort on

$direction

string

The direction to sort on (ASC or DESC)

Returns

Deletes an entity.

delete(Entity $entity) : boolean

Parameters

$entity

\Cactus\Entity

The entity to delete

Returns

booleanWas the delete successful?

Filters the data to make sure only fields that are specified in the mapper get set in the query.

filter(mixed $data, array $columns) : array
Inherited

inherited_from \Cactus\Mapper::filter()

Parameters

$data

mixed

The data to filter.

$columns

array

The columns to filter on.

Returns

arrayThe filtered data

Gets all of the records that satisfy the search parameters.

find(array $params) : \Cactus\Collection

Parameters

$params

array

The search parameters

Returns

Attempt to get a row of data by using the passed in key.

get(mixed $key) : \Cactus\Entity

Parameters

$key

mixed

The value of the primary key that is used to find the data

Returns

Gets the column list of the mapper.

getColumns() : array
Inherited

inherited_from \Cactus\Mapper::getColumns()

Returns

array

Gets the validation rules.

getValidationRules() : array
Inherited

inherited_from \Cactus\Mapper::getValidationRules()

Returns

array

Saves an entity.

save(Entity $entity) : mixed

Parameters

$entity

\Cactus\Entity

The entity to save

Returns

mixedcreate = array($id, $affected) | update = $affected

Creates a new row.

create(Entity $entity) : array

Parameters

$entity

\Cactus\Entity

The entity to create

Returns

arrayarray($id, $affected)

Takes the result array and converts it and makes a collection out of it.

formCollection(array $result) : \Cactus\Collection
Inherited

inherited_from \Cactus\Mapper::formCollection()

Parameters

$result

array

An array of results

Returns

An initilization function so we don't have to override the constructor.

init() 
Inherited

inherited_from \Cactus\Mapper::init()

Prepares the data to return to the data store (as strings).

prepareData(Entity $entity) : array
Inherited

inherited_from \Cactus\Mapper::prepareData()

Parameters

$entity

\Cactus\Entity

The entity to prepare

Returns

arrayThe modified/filtered/reverted data...

Updates an existing entity.

update(Entity $entity) : int

Parameters

$entity

\Cactus\Entity

The entity to update

Returns

intAffected rows

 Properties

 

The adapter used to fetch data

$adapter : \Cactus\Adapter
Inherited

inherited_from \Cactus\Mapper::$$adapter
 

The object class to return rows as

$objectClass : string
Inherited

inherited_from \Cactus\Mapper::$$objectClass
 

A listing of columns in the data

$columns : array
Inherited

inherited_from \Cactus\Mapper::$$columns
 

The name of the primary key column

$primary_key : string
Inherited

inherited_from \Cactus\Mapper::$$primary_key
 

A list of validation rules.

$rules : array
Inherited

inherited_from \Cactus\Mapper::$$rules
 

The database table

$table : string
Inherited

inherited_from \Cactus\Mapper::$$table