Fix php comments
[civicrm-core.git] / CRM / Core / Smarty / plugins / modifier.print_array.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Smarty print_array modifier plugin
20 *
21 * Type: modifier<br>
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
26 * @param int $depth
27 * @param int $length
28 * @return string
29 */
30 function smarty_modifier_print_array($var, $depth = 0, $length = 40) {
31
32 switch (gettype($var)) {
33 case 'array':
34 $results = "array(\n";
35 foreach ($var as $curr_key => $curr_val) {
36 $depth++;
37 $results .= str_repeat(' ', ($depth + 1))
38 . "'" . $curr_key . "' => "
39 . smarty_modifier_print_array($curr_val, $depth, $length) . ",\n";
40 $depth--;
41 }
42 $results .= str_repeat(' ', ($depth + 1)) . ")";
43 break;
44
45 case 'object':
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) {
49 $depth++;
50 $results .= str_repeat('', $depth + 1)
51 . '->' . $curr_key . ' = '
52 . smarty_modifier_debug_print_var($curr_val, $depth, $length);
53 $depth--;
54 }
55 break;
56
57 case 'boolean':
58 case 'NULL':
59 case 'resource':
60 if (TRUE === $var) {
61 $results .= 'TRUE';
62 }
63 elseif (FALSE === $var) {
64 $results .= 'FALSE';
65 }
66 elseif (NULL === $var) {
67 $results .= '';
68 }
69 else {
70 $results = $var;
71 }
72 $results = $results;
73 break;
74
75 case 'integer':
76 case 'float':
77 $results = $var;
78 break;
79
80 case 'string':
81 if (strlen($var) > $length) {
82 $results = substr($var, 0, $length - 3) . '...';
83 }
84 $results = "'" . $var . "'";
85 break;
86
87 case 'unknown type':
88 default:
89 if (strlen($results) > $length) {
90 $results = substr($results, 0, $length - 3) . '...';
91 }
92 $results = "'" . $var . "'";
93 }
94 if (empty($var)) {
95 if (is_array($var)) {
96 $results = "array()";
97 }
98 elseif ($var === '0' || $var === 0) {
99 $results = 0;
100 }
101 else {
102 $results = "''";
103 }
104 }
105 return $results;
106 }