Compatibility wrapper that provides the API found in Ragnaroek's $_MIDCOM superglobal

package midcom.compat
property
property
property
property
property
property
property
property
property
property
property
property
property
property
property

 Methods

__call ($method, $arguments)

Redirect calls to the midcom_application singleton

Parameters

$method

$arguments

__get ($key)

Magic getter for service loading

Parameters

$key

__set ($key, $value)

Magic setter

Parameters

$key

$value

_set_context_data (mixed $value, int $param1, int $param2)

Update the component context
see \get_context_data()

Parameters

$value

mixedThe value to be stored

$param1

intSee get_context_data()

$param2

intSee get_context_data()

_set_current_context ($id)

Sets a new context, doing some minor sanity checking.

Parameters

$id

Returns

booleanIndicating if the switch was successful.

add_jquery_state_script (string $script, string $state)

Register JavaScript snippets to jQuery states.

Parameters

$script

stringThe code to be included in the state.

$state

stringThe state where to include the code to. Defaults to document.ready

add_jscript (string $script, $defer, $prepend)

Register JavaScript Code for output directly in the page.

Parameters

$script

stringThe code to be included directly in the page.

$defer

$prepend

add_jsfile (string $url, boolean $prepend)

Register JavaScript File for referring in the page.

Parameters

$url

stringThe URL to the file to-be referenced.

$prepend

booleanWhether to add the JS include to beginning of includes

add_jsonload (string $method)

Register a JavaScript method for the body onload event

Parameters

$method

stringThe name of the method to be called on page startup, including parameters but excluding the ';'.

add_meta_head ($attributes)

Register a metatag to be added to the head element.

@param array $attributes Array of attribute=> value pairs to be placed in the tag.

Parameters

$attributes

add_object_head (string $script, array $attributes)

Register some object tags to be added to the head element.

Parameters

$script

stringThe input between the tags.

$attributes

arrayArray of attribute=> value pairs to be placed in the tag.

add_style_head (string $script, array $attributes)

Register a styleblock / style link to be added to the head element.

Parameters

$script

stringThe input between the tags.

$attributes

arrayArray of attribute=> value pairs to be placed in the tag.

add_stylesheet (string $url, string $media)

Convenience shortcut for adding CSS files

Parameters

$url

stringThe stylesheet URL

$media

stringThe media type(s) for the stylesheet, if any

bind_view_to_object (\midcom_core_dbaobject $object, string $page_class)

Binds the current page view to a particular object.

This will automatically connect such things like metadata and toolbars to the correct object.

Parameters

$object

\midcom_core_dbaobjectThe DBA class instance to bind to.

$page_class

stringString describing page type, will be used for substyling

enable_jquery ($version)

Init jQuery

Parameters

$version

generate_error (int $httpcode, string $message)

Generate an error page.

This function is a small helper, that will display a simple HTML Page reporting the error described by $httpcode and $message. The $httpcode is also used to send an appropriate HTTP Response.

For a list of the allowed HTTP codes see the MIDCOM_ERR... constants

Note: This function will call _midcom_stop_request() after it is finished.

see \midcom_exception_handler::show()

Parameters

$httpcode

intThe error code to send.

$message

stringThe message to print.

generate_host_url ($host)

Parameters

$host

get_all_contexts ()

Returns the complete context data array

Returns

arrayThe data of all contexts

get_component_loader ()

Return the reference to the component loader.

Returns

\midcom_helper__componentloaderThe reference of the component loader in use.

get_context_data (int $param1, int $param2)

Access the MidCOM component context

Parameters

$param1

intparam1 Either the ID of the context (two parameters) or the key requested (one parameter).

$param2

intparam2 Either the key requested (two parameters) or null (one parameter, the default).

Returns

mixedThe content of the key being requested.

get_current_context ()

Returns the ID of the currently active context.

This is false if there is no context running.

Returns

intThe context ID.

get_custom_context_data (int $param1, int $param2)

Retrieve arbitrary, component-specific information in the component context

Parameters

$param1

intSee get_context_data()

$param2

intSee get_context_data()

Returns

mixedThe requested value, which is returned by Reference!

get_service (string $name)

Return a reference to a given service.

Returns the MidCOM Object Service indicated by $name. If the service cannot be found, an HTTP 500 is triggered.

See the documentation of the various services for further details.

Parameters

$name

stringThe name of the service being requested.

Returns

mixedA reference(!) to the service requested.

load_library (string $path)

Load a code library

This will load the pure-code library denoted by the MidCOM Path $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 by it.

Common example:

midcom::get('componentloader')->load_library('midcom.helper.datamanager');

Parameters

$path

stringThe name of the code library to load.

Returns

booleanIndicates whether the library was successfully loaded.

print_head_elements ()

Echo the _head elements added.

print_jquery_statuses ()

Echo the jquery statuses

print_jsonload ()

Echo the registered javascript code.

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 you add an absolute URL starting with a "/", it will automatically add an http[s]://$servername:$server_port in front of that URL; note that the server_port is optional and only added if non-standard ports are used. If the url does not start with http[s], 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

serve_attachment (\MidgardAttachment $attachment, int $expires)

Deliver a blob to the client.

This is a replacement for mgd_serve_attachment that should work around most of its bugs: It is missing all important HTTP Headers concerning file size, modification date and expiration. It will add the following HTTP Headers:

  • Cache-Control: public max-age=$expires
  • Expires: GMT Date $now+$expires
  • Last-Modified: GMT Date of the last modified timestamp of the Attachment
  • Content-Length: The Length of the Attachment in Bytes
  • Accept-Ranges: none

This should enable caching of browsers for Navigation images and so on. You can influence the expiration of the served attachment with the parameter $expires. It is the time in seconds till the client should refetch the file. The default for this is 24 hours. If you set it to "0" caching will be prohibited by changing the sent headers like this:

  • Pragma: no-cache
  • Cache-Control: no-cache
  • Expires: Current GMT Date

If expires is set to -1, no expires header gets sent.

Parameters

$attachment

\MidgardAttachment&$attachment A reference to the attachment to be delivered.

$expires

intHTTP-Expires timeout in seconds, set this to 0 for uncacheable pages, or to -1 for no Expire header.

serve_snippet (\MidgardSnippet $snippet)

Deliver a snippet to the client.

This function can serve the code field of an arbitrary snippet. There is no checking on permissions done here, the callee has to ensure this.

Two parameters can be used to influence the behavior of this method: "midcom/content-type" will set the content-type header sent with the code field's content. If this is not set, application/octet-stream is used as a default. "midcom/expire" is a count of seconds used for content expiration, both for the HTTP headers and for the caching engine. If this is no valid integer or less then or equal to zero or not set, the value is set to "1".

The last modified header is created by using the revised timestamp of the snippet.

Remember to also set the parameter "midcom/allow_serve" to "true" to clear the snippet for serving.

Parameters

$snippet

\MidgardSnippet&$snippet The snippet that should be delivered to the client.

set_custom_context_data (mixed $key, mixed $value, mixed $contextid)

Store arbitrary, component-specific information in the component context

Parameters

$key

mixedThe key associated to the value or the context id

$value

mixed&$value The value to store. (This is stored by-reference!)

$contextid

mixedThe key if a context was specified as first parameter

set_pagetitle (string $string)

Sets the page title for the current context.

This can be retrieved by accessing the component context key MIDCOM_CONTEXT_PAGETITLE.

Parameters

$string

stringThe title to set.

substyle_append (string $newsub)

Appends a substyle after the currently selected component style.

Appends a substyle after the currently selected component style, effectively enabling a depth of more then one style during substyle selection. This is only effective if done during the handle phase of the component and allows the component. The currently selected substyle therefore is now searched one level deeper below "subStyle".

The system must have completed the CAN_HANDLE Phase before this function will be available.

Parameters

$newsub

stringThe substyle to append.

substyle_prepend (string $newsub)

Prepends a substyle before the currently selected component style.

Prepends a substyle before the currently selected component style, effectively enabling a depth of more then one style during substyle selection. This is only effective if done during the handle phase of the component and allows the component. The currently selected substyle therefore is now searched one level deeper below "subStyle".

The system must have completed the CAN_HANDLE Phase before this function will be available.

Parameters

$newsub

stringThe substyle to prepend.