\midcom_services_dbclassloader

<b>How to write database class definitions:</b>

The general idea is to provide MidCOM with a way to hook into every database interaction between the component and the Midgard core.

Since PHP does not allow for multiple inheritance (which would be really useful here), a decorator pattern is used, which connects the class you actually use in your component and the original MgdSchema class while at the same time routing all function calls through midcom_core_dbaobject.

The class loader does not require much information when registering classes: An example declaration looks like this:

Array ( 'midgard_article' => 'midcom_db_article' )

The key is the MgdSchema class name from that you want to use. The class specified must exist.

The value is the name of the MidCOM base class you intend to create. It is checked for basic validity against the PHP restrictions on symbol naming, but the class itself is not checked for existence. You must declare the class as listed at all times, as typecasting and detection is done using this metadata property in the core.

Inherited class requirements

The classes you inherit from the intermediate stub classes must at this time satisfy one requirement: You have to declare the midcom and mgdschema classnames:

class midcom_db_article extends midcom_core_dbaobject { public $midcom_class_name = CLASS; public $mgdschema_class_name = 'midgard_article';

Summary

Methods
Properties
Constants
is_mgdschema_object()
get_component_for_class()
get_midcom_class_name_for_mgdschema_object()
get_mgdschema_class_name_for_midcom_class()
is_midcom_db_object()
get_component_classes()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

is_mgdschema_object()

is_mgdschema_object(object  $object) : boolean

Simple helper to check whether we are dealing with a MgdSchema or MidCOM DBA object or a subclass thereof.

Parameters

object $object

The object to check

Returns

boolean —

true if this is a MgdSchema object, false otherwise.

get_component_for_class()

get_component_for_class(string  $classname) : string

Get component name associated with a class name to get its DBA classes defined

Parameters

string $classname

Class name to load a component for

Returns

string —

component name if found for the class, false otherwise

get_midcom_class_name_for_mgdschema_object()

get_midcom_class_name_for_mgdschema_object(string|object  $object) : string

Get a MidCOM DB class name for a MgdSchema Object.

Parameters

string|object $object

The object (or classname) to check

Returns

string —

The corresponding MidCOM DB class name, false otherwise.

get_mgdschema_class_name_for_midcom_class()

get_mgdschema_class_name_for_midcom_class(string  $classname) : string

Get an MgdSchema class name for a MidCOM DBA class name

Parameters

string $classname

The MidCOM DBA classname to check

Returns

string —

The corresponding MidCOM DBA class name, false otherwise.

is_midcom_db_object()

is_midcom_db_object(object|string  $object) : boolean

Simple helper to check whether we are dealing with a MidCOM Database object or a subclass thereof.

Parameters

object|string $object

The object (or classname) to check

Returns

boolean —

true if this is a MidCOM Database object, false otherwise.

get_component_classes()

get_component_classes(  $component) 

Parameters

$component