check return value of hook

no return value will be discarded, array and objects are put into an array, strings are concatened
This commit is contained in:
Uwe Steinmann 2017-05-02 18:29:47 +02:00
parent 7c7dfc1411
commit 9ab19afe03
2 changed files with 52 additions and 20 deletions

41
inc/inc.ClassHook.php Normal file
View File

@ -0,0 +1,41 @@
<?php
/**
* Implementation of hook response class
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2017 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Parent class for all hook response classes
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2017 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_Hook_Response {
protected $data;
protected $error;
public function __construct($error = false, $data = null) {
$this->data = $data;
$this->error = $error;
}
public function setData($data) {
$this->data = $data;
}
public function getData() {
return $this->data;
}
}

View File

@ -13,6 +13,8 @@
* @version Release: @package_version@ * @version Release: @package_version@
*/ */
require_once "inc/inc.ClassHook.php";
/** /**
* Parent class for all view classes * Parent class for all view classes
* *
@ -92,37 +94,26 @@ class SeedDMS_View_Common {
switch(func_num_args()) { switch(func_num_args()) {
case 1: case 1:
$tmpret = $hookObj->$hook($this); $tmpret = $hookObj->$hook($this);
if(is_string($tmpret))
$ret .= $tmpret;
else
$ret = $tmpret;
break; break;
case 2: case 2:
$tmpret = $hookObj->$hook($this, func_get_arg(1)); $tmpret = $hookObj->$hook($this, func_get_arg(1));
if(is_string($tmpret))
$ret .= $tmpret;
else
$ret = $tmpret;
break; break;
case 3: case 3:
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2)); $tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2));
if(is_string($tmpret))
$ret .= $tmpret;
else
$ret = $tmpret;
break; break;
case 4: case 4:
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3)); $tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3));
if(is_string($tmpret))
$ret .= $tmpret;
else
$ret = $tmpret;
break; break;
default: default:
case 5: case 5:
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4)); $tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4));
break;
}
if($tmpret) {
if(is_string($tmpret)) if(is_string($tmpret))
$ret .= $tmpret; $ret .= $tmpret;
elseif(is_array($tmpret) || is_object($tmpret))
$ret = ($ret === null) ? $tmpret : array_merge($ret, $tmpret);
else else
$ret = $tmpret; $ret = $tmpret;
} }