\midcom_helper__dbfactory

This class contains various factory methods to retrieve objects from the database.

The only instance of this class you should ever use is available through midcom::get()->dbfactory.

Summary

Methods
Properties
Constants
get_object_by_guid()
get_cached()
new_collector()
new_query_builder()
convert_midgard_to_midcom()
convert_midcom_to_midgard()
is_a()
get_parent()
get_parent_data()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
_get_parent_guid_cached()
_get_parent_guid_uncached()
_get_parent_guid_uncached_static()
_load_guid()
_get_parent_candidates()
$_parent_mapping
$_parent_candidates
N/A

Properties

$_parent_mapping

$_parent_mapping : array

ID => GUID cache for parents

Type

array

$_parent_candidates

$_parent_candidates : array

Cache for possible parent configurations per mgdschema class

Type

array

Methods

get_object_by_guid()

get_object_by_guid(string  $guid) : \midcom_core_dbaobject

This is a replacement for the original midgard_object_class::get_object_by_guid method, which takes the MidCOM DBA system into account.

Parameters

string $guid

The object GUID.

Returns

\midcom_core_dbaobject

A MidCOM DBA object if the set GUID is known

get_cached()

get_cached(string  $classname, mixed  $src) : \midcom_core_dbaobject

Retrieve a reference to an object, uses in-request caching

Parameters

string $classname

Which DBA are we dealing with

mixed $src

GUID of object (ids work but are discouraged)

Returns

\midcom_core_dbaobject

reference to object

new_collector()

new_collector(string  $classname, string  $domain = null, mixed  $value = null) : \midcom_core_collector

This function will determine the correct type of midgard_collector that has to be created. It will also call the _on_prepare_new_collector event handler.

Parameters

string $classname

The name of the class for which you want to create a collector.

string $domain

The domain property of the collector instance

mixed $value

Value match for the collector instance

Returns

\midcom_core_collector

The initialized instance of the collector.

new_query_builder()

new_query_builder(string  $classname) : \midcom_core_querybuilder

This function will determine the correct type of midgard_query_builder that has to be created. It will also call the _on_prepare_new_query_builder event handler.

Parameters

string $classname

The name of the class for which you want to create a query builder.

Returns

\midcom_core_querybuilder

The initialized instance of the query builder.

convert_midgard_to_midcom()

convert_midgard_to_midcom(\midgard\portable\api\mgdobject  $object) : \midcom_core_dbaobject

Convert MgdSchema object into a MidCOM DBA object.

If the conversion cannot be done for some reason, the function returns null and logs an error. We also ensure that the corresponding component has been loaded.

Parameters

\midgard\portable\api\mgdobject $object

MgdSchema Object

Returns

\midcom_core_dbaobject

convert_midcom_to_midgard()

convert_midcom_to_midgard(\midcom_core_dbaobject  $object) : \midgard\portable\api\mgdobject

Helper function, it takes a MidCOM DBA object and converts it into an MgdSchema object.

If the conversion cannot be done for some reason, the function throws an error.

Parameters

\midcom_core_dbaobject $object

MidCOM DBA Object

Returns

\midgard\portable\api\mgdobject —

MgdSchema Object

is_a()

is_a(mixed  $object, string  $class) : boolean

This is a helper for emulating is_a() functionality with MidCOM DBA objects that are decorators.

This method can be used to check whether an object is of a MidCOM DBA or MgdSchema type

Parameters

mixed $object

MgdSchema or MidCOM DBA object

string $class

Class to check the instance against

Returns

boolean

get_parent()

get_parent(\midcom_core_dbaobject  $object) : \midcom_core_dbaobject|null

Returns the parent object. Tries to utilize the Memcache data, loading the actual information only if it is not cached.

Parameters

\midcom_core_dbaobject $object

The DBA object we're working on

Returns

\midcom_core_dbaobject|null —

Parent if found, otherwise null

get_parent_data()

get_parent_data(mixed  $object, string  $class = null) : array

Determines the parent GUID for an existing GUID according to the MidCOM content tree rules.

It tries to look up the GUID in the memory cache, only if this fails, the regular content getters are invoked.

Parameters

mixed $object

Either a MidCOM DBA object instance, or a GUID string.

string $class

class name of object if known (so we can use get_parent_guid_uncached_static and avoid instantiating full object)

Returns

array —

The parent GUID and class (value might be null, if this is a top level object).

_get_parent_guid_cached()

_get_parent_guid_cached(  $object_guid,   $the_object,   $class = null) 

Parameters

$object_guid
$the_object
$class

_get_parent_guid_uncached()

_get_parent_guid_uncached(\midcom_core_dbaobject  $object) 

Parameters

\midcom_core_dbaobject $object

_get_parent_guid_uncached_static()

_get_parent_guid_uncached_static(  $object_guid,   $class_name) 

Get the GUID of the object's parent. This is done by reading up or parent property values, which will give us the parent's ID

Parameters

$object_guid
$class_name

_load_guid()

_load_guid(  $target_class,   $target_property,   $link_value) 

Parameters

$target_class
$target_property
$link_value

_get_parent_candidates()

_get_parent_candidates(  $classname) 

Parameters

$classname