Main controlling instance of the MidCOM Framework

package midcom

 Methods

codeinit ()

Initialize the URL parser and process the request.

This function must be called before any output starts.

see \_process()

content ()

Display the output of the component

This function must be called in the content area of the Style template, usually <(content)>.

disable_limits ()

Helper function that raises some PHP limits for resource-intensive tasks

dynamic_load (string $url, array $config, $pass_get)

Dynamically execute a subrequest and insert its output in place of the function call.

Important Note As with the Midgard Parser, dynamic_load strips a trailing .html from the argument list before actually parsing it.

It tries to load the component referenced with the URL $url and executes it as if it was used as primary component. Additional configuration parameters can be appended through the parameter $config.

This is only possible if the system is in the Page-Style output phase. It cannot be used within code-init or during the output phase of another component.

Example code, executed on a site's homepage, it will load the news listing from the given URL and display it using a substyle of the node style that is assigned to the loaded one:

$blog = '/blog/latest/3/';
$substyle = 'homepage';
midcom::get()->dynamic_load("/midcom-substyle-{$substyle}/{$blog}");

Results of dynamic_loads are cached, by default with the system cache strategy but you can specify separate cache strategy for the DL in the config array like so

midcom::get()->dynamic_load("/midcom-substyle-{$substyle}/{$newsticker}", array('cache_module_content_caching_strategy' => 'public'))

You can use only less specific strategy than the global strategy, ie basically you're limited to 'memberships' and 'public' as values if the global strategy is 'user' and to 'public' the global strategy is 'memberships', failure to adhere to this rule will result to weird cache behavior.

Parameters

$url

stringThe URL, relative to the Midgard Page, that is to be requested.

$config

arrayA key=>value array with any configuration overrides.

$pass_get

Returns

intThe ID of the newly created context.

finish ()

Exit from the framework, execute after all output has been made.

Does all necessary clean-up work. Must be called after output is completed as the last call of any MidCOM Page. Best Practice: call it at the end of the ROOT style element.

WARNING: Anything done after calling this method will be lost.

get_host_name ()

Retrieves the name of the current host, fully qualified with protocol and port.

Returns

stringFull Hostname (http[s]://www.my.domain.com[:1234])

get_host_prefix ()

Return the prefix required to build relative links on the current site.

This includes the http[s] prefix, the hosts port (if necessary) and the base url of the main host. This is not necessarily the currently active MidCOM Page however, use the get_page_prefix() function for that.

e.g. something like http[s]://www.domain.com[:8080]/host_prefix/

Returns

stringThe host's root page URL prefix.

get_page_prefix ()

Return the prefix required to build relative links on the current site.

This includes the http[s] prefix, the hosts port (if necessary) and the base url of the Midgard Page. Be aware, that this does not point to the base host of the site.

e.g. something like http[s]://www.domain.com[:8080]/host_prefix/page_prefix/

Returns

stringThe current MidCOM page URL prefix.

get_status ()

Get the current MidCOM processing state.

Returns

intOne of the MIDCOM_STATUS_... constants indicating current state.

header (string $header, integer $response_code)

Sends a header out to the client.

This function is syntactically identical to the regular PHP header() function, but is integrated into the framework. Every Header you sent must go through this function or it might be lost later on; this is especially important with caching.

Parameters

$header

stringThe header to send.

$response_code

integerHTTP response code to send with the header

initialize ()

Main MidCOM initialization.

Initialize the Application class. Sets all private variables to a predefined state. $node should be set to the midcom root-node GUID. $prefix can be a prefix, which is appended to midcom_connection::get_url('self') (i.e. the Midgard Page URL). This may be needed when MidCOM is run by wrapper.

relocate (string $url, string $response_code)

Relocate to another URL.

Helper function to facilitate HTTP relocation (Location: ...) headers. The helper actually can distinguish between site-local, absolute redirects and external redirects. If the url does not start with http[s] or /, it is taken as a URL relative to the current anchor prefix, which gets prepended automatically (no other characters as the anchor prefix get inserted).

Fully qualified urls (starting with http[s]) are used as-is.

Note, that this function automatically makes the page uncacheable, calls midcom_finish and exit, so it will never return. If the headers have already been sent, this will leave you with a partially completed page, so beware.

Parameters

$url

stringThe URL to redirect to, will be preprocessed as outlined above.

$response_code

stringHTTP response code to send with the relocation, from 3xx series

set_status (int $status)

Manually override the current MidCOM processing state.

Don't use this unless you know what you're doing

Parameters

$status

intOne of the MIDCOM_STATUS_... constants indicating current state.

_output ()

Execute the output callback.

Launches the output of the currently selected component. It is collected in an output buffer to allow for relocates from style elements.

It executes the content_handler that has been determined during the handle phase. It fetches the content_handler from the Component Loader class cache.

_process (\midcom_core_context $context)

Process the request

Basically this method will parse the URL and search for a component that can handle the request. If one is found, it will process the request, if not, it will report an error, depending on the situation.

Details: The logic will traverse the node tree and for each node it will load the component that is responsible for it. This component gets the chance to accept the request (this is encapsulated in the _can_handle call), which is basically a call to can_handle. If the component declares to be able to handle the call, its handle function is executed. Depending if the handle was successful or not, it will either display an HTTP error page or prepares the content handler to display the content later on.

If the parsing process doesn't find any component that declares to be able to handle the request, an HTTP 404 - Not Found error is triggered.

Parameters

$context

 Properties

 

boolean $skip_page_style

Set this variable to true during the handle phase of your component to not show the site's style around the component output.

This is mainly targeted at XML output like RSS feeds and similar things. The output handler of the site, excluding the style-init/-finish tags will be executed immediately after the handle phase, and midcom->finish() is called automatically afterwards, thus ending the request.

Changing this flag after the handle phase or for dynamically loaded components won't change anything.

 

string $_cached_host_name

Host name cache to avoid computing it each time.
 

string $_cached_host_prefix

Host prefix cache to avoid computing it each time.
 

string $_cached_page_prefix

Page prefix cache to avoid computing it each time.
 

int $_status

Integer constant resembling the current MidCOM state.

See the MIDCOM_STATUS_... constants