1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * XOOPS Utilities
14: *
15: * @copyright XOOPS Project (http://xoops.org)
16: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17: * @package class
18: * @subpackage utility
19: * @since 2.3.0
20: * @author Taiwen Jiang <phppp@users.sourceforge.net>
21: * @version $Id$
22: */
23:
24: class XoopsUtility
25: {
26:
27: /**
28: * @static
29: * @param mixed $handler
30: * @param mixed $data
31: * @return array|mixed
32: */
33: static function recursive($handler, $data)
34: {
35: if (is_array($data)) {
36: $return = array_map(array('XoopsUtility', 'recursive'),
37: array_fill(0, count($data), $handler), $data);
38: return $return;
39: }
40: // single function
41: if (is_string($handler)) {
42: return function_exists($handler) ? $handler($data) : $data;
43: }
44: // Method of a class
45: if (is_callable($handler)) {
46: return call_user_func($handler, $data);
47: }
48: return $data;
49: }
50: }
51: