3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Smarty print_array modifier plugin
22 * Name: print_array<br>
23 * Purpose: formats array for output in DAO files and in APIv3 Examples
24 * To find where this is used do a grep in Smarty templates for |@print_array
25 * @param array|object $var
30 function smarty_modifier_print_array($var, $depth = 0, $length = 40) {
32 switch (gettype($var)) {
34 $results = "array(\n";
35 foreach ($var as $curr_key => $curr_val) {
37 $results .= str_repeat(' ', ($depth +
1))
38 . "'" . $curr_key . "' => "
39 . smarty_modifier_print_array($curr_val, $depth, $length) . ",\n";
42 $results .= str_repeat(' ', ($depth +
1)) . ")";
46 $object_vars = get_object_vars($var);
47 $results = get_class($var) . ' Object (' . count($object_vars) . ')';
48 foreach ($object_vars as $curr_key => $curr_val) {
50 $results .= str_repeat('', $depth +
1)
51 . '->' . $curr_key . ' = '
52 . smarty_modifier_debug_print_var($curr_val, $depth, $length);
63 elseif (FALSE === $var) {
66 elseif (NULL === $var) {
81 if (strlen($var) > $length) {
82 $results = substr($var, 0, $length - 3) . '...';
84 $results = "'" . $var . "'";
89 if (strlen($results) > $length) {
90 $results = substr($results, 0, $length - 3) . '...';
92 $results = "'" . $var . "'";
98 elseif ($var === '0' ||
$var === 0) {