ICanBoogie/ActiveRecord 3.0.x
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • ActiveRecord
      • ActiveRecordCache
      • Driver
      • Property
      • Validate
        • Reader
        • Validator
        • ValidatorProvider

Classes

  • ActiveRecord

Class ActiveRecord

Active Record facilitates the creation and use of business objects whose data require persistent storage via database.

ICanBoogie\Prototyped
Extended by ICanBoogie\ActiveRecord
Namespace: ICanBoogie
Located at ActiveRecord.php

Methods summary

public
# __construct( string|ICanBoogie\ActiveRecord\Model|null $model = null )

Initializes the $model and ICanBoogie\ActiveRecord::$model_id properties.

Initializes the $model and ICanBoogie\ActiveRecord::$model_id properties.

Parameters

$model

The model managing the active record. A ICanBoogie\ActiveRecord\Model instance can be specified as well as a model identifier. If a model identifier is specified, the model is resolved when the $model property is accessed. If $model is empty, the identifier of the model is read from the ICanBoogie\ActiveRecord::MODEL_ID class constant.

Throws

InvalidArgumentException

if $model is neither a model identifier nor a ICanBoogie\ActiveRecord\Model instance.

public
# __sleep( )

Removes the $model property.

Removes the $model property.

Properties whose value are instances of the ICanBoogie\ActiveRecord class are removed from the exported properties.

public array
# __debugInfo( )

Removes model from the output, since model_id is good enough to figure which model is used.

Removes model from the output, since model_id is good enough to figure which model is used.

Returns

array
protected ICanBoogie\ActiveRecord\Model
# get_model( )

Returns the model managing the active record.

Returns the model managing the active record.

Returns

ICanBoogie\ActiveRecord\Model
protected string
# get_model_id( )

Returns the identifier of the model managing the active record.

Returns the identifier of the model managing the active record.

Returns

string
protected boolean
# get_is_new( )

Whether the record is new or not.

Whether the record is new or not.

Returns

boolean
public boolean|integer
# save( array $options = [] )

Saves the active record using its model.

Saves the active record using its model.

Parameters

$options
Save options.

Returns

boolean|integer

Primary key value of the active record, or a boolean if the primary key is not a serial.

public ICanBoogie\ActiveRecord
# assert_is_valid( )

Assert that a record is valid.

Assert that a record is valid.

Returns

ICanBoogie\ActiveRecord
$this

Throws

ICanBoogie\ActiveRecord\RecordNotValid
if the record is not valid.
public array
# create_validation_rules( )

Creates validation rules.

Creates validation rules.

Returns

array
protected array
# alter_persistent_properties( array $properties, ICanBoogie\ActiveRecord\Schema $schema )

Unless it's an acceptable value for a column, columns with null values are discarded. This way, we don't have to define every properties before saving our active record.

Unless it's an acceptable value for a column, columns with null values are discarded. This way, we don't have to define every properties before saving our active record.

Parameters

$properties
$schema
The model's extended schema.

Returns

array
The altered persistent properties
protected
# update_primary_key( array|string|integer $primary_key )

Updates primary key.

Updates primary key.

Parameters

$primary_key
public boolean
# delete( )

Deletes the active record using its model.

Deletes the active record using its model.

Returns

boolean
true if the record was deleted, false otherwise.

Throws

Exception
in attempt to delete a record from a model which primary key is empty.

Magic methods summary

public ICanBoogie\Validate\ValidationErrors
# validate( )

Validate the active record, returns an array of errors.

Validate the active record, returns an array of errors.

Returns

ICanBoogie\Validate\ValidationErrors

Constants summary

string SAVE_SKIP_VALIDATION
# 'skip_validation'
string MODEL_ID

The identifier of the model managing the record.

The identifier of the model managing the record.

# null

Properties summary

protected string $model_id

Identifier of the model managing the active record.

Identifier of the model managing the active record.

Note: Due to a PHP bug (or feature), the visibility of the property MUST NOT be private. https://bugs.php.net/bug.php?id=40412

#

Magic properties

public read-only ICanBoogie\ActiveRecord\Model $model

The model managing the active record.

public read-only string $model_id

The identifier of the model managing the active record.

public read-only boolean $is_new

Whether the record is new or not.

ICanBoogie/ActiveRecord 3.0.x API documentation generated by ApiGen