Overview

Namespaces

  • Charcoal
    • Loader
    • Model
      • Service
      • ServiceProvider
    • Source
      • Database
    • Validator

Classes

  • AbstractMetadata
  • AbstractModel
  • Collection
  • Model
  • ModelMetadata
  • ModelValidator

Interfaces

  • CollectionInterface
  • DescribableInterface
  • MetadataInterface
  • ModelInterface

Traits

  • DescribableTrait
  • Overview
  • Namespace
  • Class

Class AbstractModel

An abstract class that implements most of ModelInterface.

In addition to ModelInterface, the abstract model implements the following interfaces:

  • DescribableInterface
  • `StorableInterface
  • ValidatableInterface
  • ViewableInterface.

Those interfaces are implemented (in parts, at least) with the DescribableTrait, StorableTrait, ValidatableTrait and the ViewableTrait.

The JsonSerializable interface is fully provided by the DescribableTrait.

Charcoal\Config\AbstractEntity
Extended by Charcoal\Model\AbstractModel implements Charcoal\Model\ModelInterface, Charcoal\Model\DescribableInterface, Charcoal\Property\DescribablePropertyInterface, Psr\Log\LoggerAwareInterface, Charcoal\Source\StorableInterface, Charcoal\Validator\ValidatableInterface, Charcoal\View\ViewableInterface uses Psr\Log\LoggerAwareTrait (not available) Charcoal\Model\DescribableTrait, Charcoal\Property\DescribablePropertyTrait (not available) Charcoal\Source\StorableTrait, Charcoal\Validator\ValidatableTrait, Charcoal\View\ViewableTrait (not available)

Direct known subclasses

Charcoal\Model\Model
Abstract
Namespace: Charcoal\Model
Located at Charcoal/Model/AbstractModel.php
Methods summary
public
# __construct( array $data = null )

Parameters

$data
Dependencies.
public
# setDependencies( Pimple\Container $container )

Inject dependencies from a DI Container.

Inject dependencies from a DI Container.

Parameters

$container
A dependencies container instance.
protected array|Traversable
# setIdFromData( array|Traversable $data )

Set the object's ID from an associative array map (or any other Traversable).

Set the object's ID from an associative array map (or any other Traversable).

Useful for setting the object ID before the rest of the object's data.

Parameters

$data
The object data.

Returns

array|Traversable
The object data without the pre-set ID.
public Charcoal\Model\AbstractModel
# setData( array $data )

Sets the object data, from an associative array map (or any other Traversable).

Sets the object data, from an associative array map (or any other Traversable).

Parameters

$data
The entity data. Will call setters.

Returns

Charcoal\Model\AbstractModel
Chainable

Implementation of

Charcoal\Model\ModelInterface::setData()
public array
# data( array $propertyFilters = null )

Return the object data as an array.

Return the object data as an array.

Parameters

$propertyFilters
Optional. Property filter.

Returns

array

Implementation of

Charcoal\Model\ModelInterface::data()
public EntityInterface
# mergeData( array|Traversable $data )

Override's \Charcoal\Config\AbstractEntity's setData method to take properties into consideration.

Override's \Charcoal\Config\AbstractEntity's setData method to take properties into consideration.

Also add a special case, to merge values for l10n properties.

Parameters

$data
The data to merge.

Returns

EntityInterface
Chainable

See

\Charcoal\Config\AbstractEntity::offsetSet()
public array
# defaultData( )

Returns

array

Implementation of

Charcoal\Model\ModelInterface::defaultData()
public Charcoal\Model\AbstractModel
# setFlatData( array $flatData )

Sets the data

Sets the data

This function takes a 1-dimensional array and fill the object with its value.

Parameters

$flatData
The data, as a flat (1-dimension) array.

Returns

Charcoal\Model\AbstractModel
Chainable

Implementation of

Charcoal\Model\ModelInterface::setFlatData()
public array
# flatData( )

Returns

array

Implementation of

Charcoal\Model\ModelInterface::flatData()
public mixed
# propertyValue( string $propertyIdent )

Parameters

$propertyIdent
The property ident to get the value from.

Returns

mixed
public boolean
# saveProperties( array $properties = null )

Parameters

$properties
Optional array of properties to save. If null, use all object's properties.

Returns

boolean
public string
# loadFromL10n( string $key, mixed $value, array $langs )

Load an object from the database from its l10n key $key. Also retrieve and return the actual language that matched.

Load an object from the database from its l10n key $key. Also retrieve and return the actual language that matched.

Parameters

$key
Key pointing a column's l10n base ident.
$value
Value to search in all languages.
$langs
List of languages (code, ex: "en") to check into.

Returns

string
The matching language.

Throws

Exception
If the PDO query fails.
public boolean
# save( )

Save the object's current state to storage.

Save the object's current state to storage.

Overrides default StorableTrait save() method to also save properties.

Returns

boolean

See

Charcoal\Source\StorableTrait::save() For the "create" event.

Implementation of

Charcoal\Source\StorableInterface::save()
protected boolean
# preSave( )

StorableTrait > preSave(). Save hook called before saving the model.

StorableTrait > preSave(). Save hook called before saving the model.

Returns

boolean
protected boolean
# preUpdate( array $properties = null )

StorableTrait > preUpdate(). Update hook called before updating the model.

StorableTrait > preUpdate(). Update hook called before updating the model.

Parameters

$properties
Optional. The properties to update.

Returns

boolean
protected Charcoal\Model\MetadataInterface
# createMetadata( )

DescribableTrait > createMetadata().

DescribableTrait > createMetadata().

Returns

Charcoal\Model\MetadataInterface
protected SourceInterface
# createSource( )

StorableInterface > createSource()

StorableInterface > createSource()

Returns

SourceInterface

Throws

Exception
If the metadata source can not be found.
protected ValidatorInterface
# createValidator( array $data = null )

ValidatableInterface > create_validator().

ValidatableInterface > create_validator().

Parameters

$data
Optional.

Returns

ValidatorInterface
public ViewInterface
# createView( array $data = null )

Parameters

$data
Optional. View data.

Returns

ViewInterface
public string
# objType( )

Convert the current class name in "type-ident" format.

Convert the current class name in "type-ident" format.

Returns

string
Methods inherited from Charcoal\Model\ModelInterface
p(), properties(), property()
Methods inherited from Charcoal\Model\DescribableInterface
loadMetadata(), metadata(), metadataIdent(), setMetadata(), setMetadataIdent(), setMetadataLoader()
Methods inherited from Charcoal\Source\StorableInterface
delete(), id(), key(), load(), loadFrom(), loadFromQuery(), setId(), setKey(), source(), update()
Methods inherited from Charcoal\Validator\ValidatableInterface
setValidator(), validate(), validator()
Methods used from Charcoal\Model\DescribableTrait
generateMetadataIdent(), loadMetadata(), metadata(), metadataIdent(), metadataLoader(), setMetadata(), setMetadataIdent(), setMetadataLoader()
Methods used from Charcoal\Source\StorableTrait
delete(), id(), key(), load(), loadFrom(), loadFromQuery(), postDelete(), postSave(), postUpdate(), preDelete(), setId(), setKey(), setSource(), setSourceFactory(), source(), sourceFactory(), update()
Methods used from Charcoal\Validator\ValidatableTrait
setValidator(), validate(), validator()
Constants summary
string DEFAULT_SOURCE_TYPE
# 'database'
Properties used from Charcoal\Model\DescribableTrait
$metadata, $metadataIdent, $metadataLoader
Properties used from Charcoal\Source\StorableTrait
$id, $key, $sourceFactory
Properties used from Charcoal\Validator\ValidatableTrait
$validator
API documentation generated by ApiGen