$_component
$_component : string
The name of the component, e.g. net.nehmer.static. Should be used whenever the component's name is required instead of hardcoding it.
Baseclass to use for the component interface in MidCOM.
The class uses an event based approach for subclasses to influence the default behavior.
The actual implementation should be enough for most smaller components, as the class's behavior is widely configurable. You should not override any of the base class's interface methods if you can avoid it. If you find that an event handler is missing, please contact the MidCOM development team for some advice.
Quick start
This class does a lot of things automatically for you, described below. If you are not interested in the gory details though, here is a quick list of what you have to know (but don't complain if I have missed anything), and do these things after calling the base class constructor:
Class parameters
The following options can be used to parametrize the component's startup and operation. See the individual member documentation for now.
Class operation
This class now does an awful lot of work for you, you just need to configure it to have the right names and places to look for. It is designed to fit in the current component wildlife with as little collateral damage as possible, but as always, a 100% transparent implementation is neither wanted nor sensible.
Actually, you should not need to overwrite any event handler for almost all components I currently know of. Ultimately, this is a proxy class to the actual component code. Its main goals are to automate these tasks:
Example usage
The average component will require something like this, part one is the component manifest:
'name' => 'net.nehmer.static',
'purecode' => false,
'version' => 1,
'privileges' => Array
(
'read' => MIDCOM_PRIVILEGE_ALLOW,
'write' => [MIDCOM_PRIVILEGE_DENY, MIDCOM_PRIVILEGE_ALLOW]
),
'class_mapping' => ['mgdschema_classname' => 'midcom_classname'],
See the class midcom_core_manifest for further details.
Built on this, we add the following interface class:
class net_nehmer_static_interface extends midcom_baseclasses_components_interface
{
public function _on_reindex($topic, $config, &$indexer)
{
$qb = midcom::get()->dbfactory->new_query_builder('midcom_db_article');
$qb->add_constraint('topic', '=', $topic->id);
$articles = $qb->execute();
$datamanager = datamanager::from_schemadb($config->get('schemadb'));
foreach ($articles as $article) {
try {
$datamanager->set_storage($article);
} catch (midcom_error $e) {
$e->log();
continue;
}
$document = $indexer->new_document($datamanager);
$document->topic_guid = $topic->guid;
$document->topic_url = $node[MIDCOM_NAV_FULLURL];
$document->read_metadata_from_object($datamanager->storage->object);
$document->component = $topic->component;
$indexer->index($document);
}
}
}
$_nap_instance : \midcom_baseclasses_components_navigation
The NAP interface instance from the component, initialized on demand.
get_workflow(string $identifier, array $options = array()) : \midcom\workflow\dialog
string | $identifier | |
array | $options |
configure(mixed $configuration, integer $contextid)
Configures the component for usage. The configuration is merged, and, if necessary, an existing handler object is purged.
mixed | $configuration | A configuration data list, suitable for merging with a midcom_helper_configuration object. |
integer | $contextid | The ID of the context we are associated with. |
can_handle(\midcom_db_topic $current_object, \Symfony\Component\HttpFoundation\Request $request, integer $contextid) : boolean
Relays the can_handle call to the component, instantiating a new site class. It will execute can_handle of that class, returning its result to MidCOM.
\midcom_db_topic | $current_object | The topic in question. |
\Symfony\Component\HttpFoundation\Request | $request | |
integer | $contextid | The id of the context we are operating in. |
True, if the component can handle the request, false otherwise.
handle() : \midcom_response|boolean
Relays the handle call to the component.
True, if the component successfully handle the request, false otherwise.
set_object(\midcom_db_topic $object) : boolean
Relays the set_object call to the nap instance. Checks if the NAP instance has already been created beforehand.
\midcom_db_topic | $object | The midcom_db_topic that should be processed. |
Indicating success.
reindex(\midcom_db_topic $topic) : boolean
Initiate a reindex run for the given component and topic.
\midcom_db_topic | $topic | The topic that should be reindexed. |
Indicating success.
get_config_for_topic(\midcom_db_topic $topic = null) : \midcom_helper_configuration
Get the full configuration set active for a given topic.
If no topic is passed, the system wide default configuration is returned.
Be aware, that this call does not check if the passed topic is actually handled by this component, as it is theoretically possible for components to drop configuration information on other topics as well.
\midcom_db_topic | $topic | The topic which should be queried, omit to get the systemwide defaults. |
MidCOM configuration object
trigger_watch(integer $operation, \midcom_core_dbaobject $object)
Delegate all watched operations, in two phases. First, the general _on_watched_operation handler is called, to allow for handling generic operations. After that, the individual watches are called, to allow for more specific processing.
integer | $operation | The operation that has occurred. |
\midcom_core_dbaobject | $object | The object on which the operation occurred. The system will do is_a checks against any registered class restriction on the watch. |
_on_watched_operation(integer $operation, \midcom_core_dbaobject $object)
This function is triggered at the end of the request for each watched operation that has been done during the request.
It will be called once per operation and unique object, where object uniqueness is determined by the combination of object class and guid. The object has been refreshed before being passed to this event handler.
integer | $operation | The operation identifier (one of the MIDCOM_OPERATION constants) which applies. |
\midcom_core_dbaobject | $object | The object on which the operation has occurred. |
_on_watched_dba_create(\midcom_core_dbaobject $object)
This function is triggered at the end of the request for each watched create operation that has been done during the request.
It will be called once per operation and unique object, where object uniqueness is determined by the combination of object class and guid. The object has been refreshed before being passed to this event handler.
It is called after the generic _on_watched_operation event handler.
\midcom_core_dbaobject | $object | The object on which the operation has occurred. |
_on_watched_dba_update(\midcom_core_dbaobject $object)
This function is triggered at the end of the request for each watched update operation that has been done during the request.
It will be called once per operation and unique object, where object uniqueness is determined by the combination of object class and guid. The object has been refreshed before being passed to this event handler.
It is called after the generic _on_watched_operation event handler.
\midcom_core_dbaobject | $object | The object on which the operation has occurred. |
_on_watched_dba_delete(\midcom_core_dbaobject $object)
This function is triggered at the end of the request for each watched delete operation that has been done during the request.
It is called after the generic _on_watched_operation event handler.
\midcom_core_dbaobject | $object | The object on which the operation has occurred. |
_on_watched_dba_import(object $object)
This function is triggered at the end of the request for each watched import operation that has been done during the request.
It is called after the generic _on_watched_operation event handler.
object | $object | The object on which the operation has occurred. |
_on_reindex(\midcom_db_topic $topic, \midcom_helper_configuration $config, $indexer) : boolean
Reindex the given topic. The complete configuration set is already available in $config. The original index records are already deleted, so you do not need to bother about this.
The default event handler does nothing.
\midcom_db_topic | $topic | The topic to reindex. |
\midcom_helper_configuration | $config | The configuration associated with this topic. |
$indexer |
Indicating success.