\midcom_helper__componentloader

This class is a Factory that is responsible for loading and establishing the interface to a MidCOM Component.

Working with components

Normally, two things are important when you deal with other components:

First, if you want to list other components, or for example check whether they are available, you should use the component manifest listing, known as $manifests. It gives you all meta-information about the components.

This should actually suffice for most normal operations.

If you develop framework tools (like administration interfaces), you will also need access to the component interface class, which can be obtained by get_interface_class(). This class is derived from the component interface baseclass and should give you everything you need to work with the component and its information itself.

Other than that, you should not have to deal with the components, perhaps with the only exception of is_loaded() and load() to ensure other components are loaded in case you need them and they are not a pure-code library.

Loading components

When the component loader receives a request it roughly works in three stages:

  1. Verify that the given component is valid in terms of the MidCOM Specification.
  2. Initialize the Component. Check whether all required concept classes exist.
  3. Return the various interface concepts upon each request from the framework.

Stage 1 will do all basic sanity checking. If anything is missing, step 1 fails and the componentloader refuses to load the component.

Stage 2 will then load the interfaces.php file from the midcom directory. The existence of all required Interface classes is then checked. If this check is successful, the concrete classes of the various interface concepts are instantiated and stored internally. The component is initialized by the call to initialize() which should load everything necessary.

Stage 3 is the final stage where the loader stays in memory in order to return the loaded component's Interface instances upon request.

In case you need an instance of the component loader to verify or transform component paths, use midcom::get()->componentloader

Summary

Methods
Properties
Constants
load()
load_graceful()
load_library()
is_loaded()
is_installed()
register_component()
get_interface_class()
path_to_snippetpath()
path_to_prefix()
list_loaded_components()
load_all_manifests()
get_manifests()
get_all_manifest_customdata()
get_component_icon()
$manifests
No constants found
No protected methods found
No protected properties found
N/A
_load()
_register_manifest()
$_loaded
$_tried_to_load
$_interface_classes
N/A

Properties

$manifests

$manifests : array<mixed,\midcom_core_manifest>

This lists all available components in the systems in the form of their manifests, indexed by the component name. Whenever possible you should refer to this listing to gain information about the components available.

This information is loaded during startup.

Type

array<mixed,\midcom_core_manifest>

$_loaded

$_loaded : Array

This indexed array stores the MidCOM paths of all loaded components. Its elements are used as keys for the cache storage.

Type

Array

$_tried_to_load

$_tried_to_load : array

This array contains a list of components that were tried to be loaded.

The components are added to this list even if the system only tried to load it and failed. This way we protect against duplicate class errors and the like if a defective class is tried to be loaded twice.

The array maps component names to loading results. The loading result is either false or true as per the result of the load call.

Type

array

$_interface_classes

$_interface_classes : array<mixed,\midcom_baseclasses_components_interface>

This is a part of the component cache. It stores the interface instances of the different loaded components, indexed by their MidCOM Path.

Type

array<mixed,\midcom_baseclasses_components_interface>

Methods

load()

load(string  $path) 

Invoke _load directly. If the loading process is unsuccessful, throw midcom_error.

Parameters

string $path

The component to load explicitly.

load_graceful()

load_graceful(string  $path) : boolean

Invoke _load directly. If the loading process is unsuccessful, false is returned.

Parameters

string $path

The component to load explicitly.

Returns

boolean —

Indicating success.

load_library()

load_library(string  $path) : boolean

This will load the pure-code library denoted by $path. It will return true if the component truly was a pure-code library, false otherwise.

If the component loader cannot load the component, midcom_error will be thrown.

Common example:

midcom::get()->componentloader->load_library('org.openpsa.httplib');

Parameters

string $path

The name of the code library to load.

Returns

boolean —

Indicates whether the library was successfully loaded.

is_loaded()

is_loaded(string  $path) : boolean

Returns true if the component identified by the MidCOM path $url is already loaded and available for usage.

Parameters

string $path

The component to be queried.

Returns

boolean —

true if it is loaded, false otherwise.

is_installed()

is_installed(string  $path) : boolean

Returns true if the component identified by the MidCOM path $url is installed.

Parameters

string $path

The component to be queried.

Returns

boolean —

true if it is loaded, false otherwise.

register_component()

register_component(  $name,   $path) 

Parameters

$name
$path

get_interface_class()

get_interface_class(string  $path) : \midcom_baseclasses_components_interface

Returns an instance of the specified component's interface class. The component is given in $path as a MidCOM path.

Such an instance will be cached by the framework so that only one instance is always active for each component. Missing components will be dynamically loaded into memory.

Parameters

string $path

The component name.

Returns

\midcom_baseclasses_components_interface

The concept class in question

path_to_snippetpath()

path_to_snippetpath(string  $component_name) : string

Convert a component path (net.nehmer.blog) to a snippetpath (/net/nehmer/blog).

Parameters

string $component_name

Input string.

Returns

string —

Converted string.

path_to_prefix()

path_to_prefix(string  $path) : string

Convert a component path (net.nehmer.blog) to a class prefix (net_nehmer_blog).

Parameters

string $path

Input string.

Returns

string —

Converted string.

list_loaded_components()

list_loaded_components() : Array

Retrieve a list of all loaded components. The Array will contain an unsorted collection of MidCOM Paths.

Returns

Array —

List of loaded components

load_all_manifests()

load_all_manifests() 

This function is called during system startup and loads all component manifests. The list of manifests to load is determined using a find shell call and is cached using the memcache cache module.

This method is executed during system startup by the framework. Other parts of the system must not access it.

get_manifests()

get_manifests(\midcom_config  $config = null) 

This function is called from the class manifest loader in case of a cache miss.

Parameters

\midcom_config $config

The configuration object (useful for calling this function without initializing midcom)

get_all_manifest_customdata()

get_all_manifest_customdata(string  $component, boolean  $showempty = false) : Array

Build a complete set of custom data associated with a given component identifier. In case a given component does not have the key set and the boolean parameter is set to true, an empty array is added implicitly.

Parameters

string $component

The custom data component index to look for.

boolean $showempty

Set this flag to true to get an (empty) entry for all components which don't have customdata applicable to the component index given. This is disabled by default.

Returns

Array —

All found component data indexed by known components.

get_component_icon()

get_component_icon(  $component,   $provide_fallback = true) 

Parameters

$component
$provide_fallback

_load()

_load(string  $path) : boolean

Load the component specified by $path. If the component could not be loaded successfully due to integrity errors, it will return false.

Parameters

string $path

The component to load.

Returns

boolean —

Indicating success.

_register_manifest()

_register_manifest(\midcom_core_manifest  $manifest) 

Register manifest data.

All default privileges are made known to ACL, the watches are registered

Parameters

\midcom_core_manifest $manifest

the manifest object to load.