Class mr_helper

Description

MR Helper

This class is namespace driven. A namespace is a relative directory path from Moodle's directory root. Examples:

  • local/mr/framework
  • blocks/helloworld
This model controls access to classes defined in local/mr/framework/helper/ or in /path/to/current/namespace/helper/ and those classes methods.

Each namespace has its own copy of any helper class used and for each namespace, a helper class is only instantiated once.

The MR Helper can be used in two ways:

  1. mr_helper->HELPERNAME->HELPERMETHOD() - these are routed through __get()
  2. mr_helper->HELPERNAME() - these are routed through __call()
Examples:
  1.  <?php
  2.       $helper new mr_helper('blocks/helloworld');
  3.       $helper->world->say_hello()// Call blocks_helloworld_helper_world::say_hello()
  4.       $helper->world->direct();    // Call blocks_helloworld_helper_world::direct()
  5.       $helper->world();            // Call blocks_helloworld_helper_world::direct() (Short cut)
  6.  
  7.       // If a helper is not found in blocks/helloworld/helper/
  8.       // then we will look in local/mr/framework/helper:
  9.       $helper->buffer('foo');      // Call mr_helper_buffer::direct()
  10.  ?>

  • author: Mark Nielsen

Located in /helper.php (line 67)


	
			
Variable Summary
static array $instances
string $namespace
Method Summary
static mr_helper get ([string $namespace = NULL])
mr_helper __construct ([string $namespace = NULL])
mixed __call (string $name, array $arguments)
mr_helper_abstract __get (string $name)
Variables
static array $instances = array() (line 86)

Helper instances

Instances are organized by namespace then by the helper name. Each helper is created only once per namespace.

Example: array('blocks/helloworld' => array('world' => new blocks_helloworld_helper_world()))

  • access: protected
string $namespace (line 93)

Current namespace for including helpers

  • access: protected
Methods
static get (line 132)

Static interface for getting an instance of mr_helper

This is useful when you need to quickly call a single helper method. Example:

  1.  <?php
  2.       $return mr_helper::get('blocks/helloworld')->world();
  3.  ?>

  • access: public
static mr_helper get ([string $namespace = NULL])
  • string $namespace: Current namespace, EG: blocks/reports
Constructor __construct (line 102)

Automatically add the load helper since this model uses it to load other helpers

  • access: public
mr_helper __construct ([string $namespace = NULL])
  • string $namespace: Current namespace, EG: blocks/reports
__call (line 173)

Call a helper's direct method

  • throws: coding_exception
  • access: public
mixed __call (string $name, array $arguments)
  • string $name: Helper name
  • array $arguments: Direct method args
__get (line 143)

Get a helper

  • throws: coding_exception
  • access: public
mr_helper_abstract __get (string $name)
  • string $name: Helper name

Documentation generated on Thu, 28 Jun 2012 16:33:48 -0700 by phpDocumentor 1.4.3