wolfcms/wolfcms — pull request #533 by marekmurawski (2013-09-28 11:16:11+00:00)
Title: Fixes Node _call and _callStatic to be usable

I assume the intetion of introducing these magic methods along with `Node::registerMethod()` was providing end user to use code like:

```
// page part / snippet / layout code:
$this->doSomethingCoolWithThisPage('very cool');
```

which would call appropriate method registered with a plugin and this way greatly simplify and extend `$this` (Page) usage in page parts / layouts / snippets by providing plugin-provided methods.

The problem with current implementation was misuse of `call_user_func` in `__call` and `__callStatic` which should be replaced with `call_user_func_array` to pass array of parameters into registered method.

Moreover `array_unshift` operates on array reference and ***returns count of array elements*** after addition instead of the ***actual array*** of method parameters prepended by object.

See the diff for proposed code, and below i provide drop-in replacement of ***skeleton/index.php*** to test the code. IMO it works as expected now.

```
/* Security measure */
if (!defined('IN_CMS')) {
exit();
}

Plugin::setInfos(array(
'id' => 'skeleton',
'title' => __('Skeleton'),
'description' => __('Provides a basic plugin implementation. (try enabling it!)'),
'version' => '1.1.0',
'license' => 'GPL',
'author' => 'Martijn van der Kleijn',
'website' => 'http://www.wolfcms.org/',
'update_url' => 'http://www.wolfcms.org/plugin-versions.xml',
'require_wolf_version' => '0.5.5'
));

Plugin::addController('skeleton', __('Skeleton'), 'admin_view', false);

/*
* Exposes usage of instanceTest($type)
* in page part/layout/snippet
*
* example:
* $this->instanceTest('h3');
*
* should echo page title wrapped in H3 html tags
*/
Page::registerMethod('instanceTest', 'skeleton_instance_test');
function skeleton_instance_test($that, $type) {
echo '<' . $type . '>' . $that->title() . '';
}

/*
* Exposes usage of class level method
* in page part/layout/snippet
*
* example:
* Page::staticTest(4);
*
* should echo page (id=4) object wrapped in PRE html tags
*/
Page::registerMethod('staticTest', 'skeleton_static_test');
function skeleton_static_test($that, $id) {
echo '

';
if ($page = $that::findById($id)) {
echo html_encode(print_r($page));
} else {
echo 'Page with id ' . $id . ' not found!';
}
echo '

';
}

/**
* TO TEST: just put the code below into a page part
*
* instanceTest('H3');
* $this->instanceTest('H2');
* $this->instanceTest('PRE');
* Page::staticTest(4);
* Page::staticTest(1234);
* ?>
*/
```