Created
July 20, 2012 04:16
-
-
Save e2thex/3148658 to your computer and use it in GitHub Desktop.
sps_drupal()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Drupal/sps | |
| /** | |
| * This is to assit in calling function outside of the sps | |
| * module that might have side effect. It allows for test to | |
| * change the function for there tests | |
| * the syntax to use is | |
| * | |
| * sps_drupal()->FUNCTIONNAME(Param1, Param2, Param3); | |
| * eg.g sps_drupal()->drupal_get_form('sps_preview_form'); | |
| * | |
| * if a param needs to be passed by reference the following syntax can be used | |
| * sps_drupal()->ref[FUNCTIONNAME](Param1, Param2, Param3); | |
| * eg.g sps_drupal()->set('drupal_get_form','sps_preview_form'); | |
| * | |
| * if a test need to reset that function it can run | |
| * sps->call['drupal_get_form'] = 'test_drupal_get_form'; | |
| * and then if something called drupal_get_form it would call | |
| * test_drupal_get_form instead. | |
| */ | |
| function sps_drupal() { | |
| $drupal = &drupal_static(__FUNCTION__); | |
| if(!$drupal) { | |
| $drupal = new \Drupal\sps\Drupal(); | |
| } | |
| return $drupal; | |
| } | |
| class Drupal implements ArrayAccess { | |
| protected $override(); | |
| public function __call($name, $args) { | |
| if (isset($this->$override[$name])) { | |
| return call_user_func_array($this->$override[$name], $args); | |
| } | |
| else { | |
| return call_user_func_array($name, $args); | |
| } | |
| } | |
| public __construct() { | |
| $this->ref = $this; | |
| } | |
| public function offsetExists ( $offset ) { | |
| return TRUE; | |
| } | |
| public function offsetGet ( $offset ) { | |
| if(!isset($this->overrides[$offset])) { | |
| return $offset; | |
| } | |
| return $this->overrides[$offset]; | |
| } | |
| public function offsetSet ( $offset , $value ) { | |
| $this->overrides[$offset] = $value; | |
| } | |
| public function offsetUnset ($offset) { | |
| unset($this->overrides[$offset]); | |
| } | |
| public function set($name, $value) { | |
| $this[$name] = $value; | |
| } | |
| public function unset($name) { | |
| unset($this[$name]) | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment