ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
inc.debug.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
42 function vd()
43 {
44  list($file, $func) = getPhpSourceCodePositionInfo(1);
45 
46  $numargs = func_num_args();
47 
48  if ($numargs == 0) {
49  return false;
50  }
51 
52  $arg_list = func_get_args();
53  $num = 1;
54 
55  include_once 'Services/Authentication/classes/class.ilAuthFactory.php';
56  if (ilAuthFactory::getContext() == ilAuthFactory::CONTEXT_CRON) {
57  $cli = true;
58  } else {
59  $cli = false;
60  }
61 
62  foreach ($arg_list as $arg) {
63  if (!$cli) {
64  $printbefore = "<pre style=\"text-align:left;\">";
65  $printbefore .= "$file - $func - variable $num:<br/>";
66  $printafter = "</pre><br/>";
67  } else {
68  $printbefore = "\n\n_________________________________________________" .
69  "_________________________________________________\n";
70  $printbefore .= "$file - $func - variable $num:\n\n";
71  $printafter = "_________________________________________________" .
72  "_________________________________________________\n\n";
73  }
74 
75  echo $printbefore;
76  var_dump($arg);
77  echo $printafter;
78  $num++;
79  }
80 
81  // BH: php 5.3 seems to not flushing the output consequently so following redirects are still performed
82  // and the output of vd() would be lost in nirvana if we not flush the output manualy
83  flush();
84  ob_flush();
85 }
86 
95 function pr($var, $name = '')
96 {
97  if ($name != '') {
98  $name .= ' = ';
99  }
100  $print = $name . print_r($var, true);
101 
102  if (ilAuthFactory::getContext() == ilAuthFactory::CONTEXT_CRON) {
103  $hr = "\n---------------------------------------------------------------\n";
104  echo $hr . $print . $hr;
105  } else {
106  echo '<pre>' . $print . '</pre>';
107  }
108 
109  // BH: php 5.3 seems to not flushing the output consequently so following redirects are still performed
110  // and the output of vd() would be lost in nirvana if we not flush the output manualy
111  flush();
112  ob_flush();
113 }
114 
124 function cf($backjumps = 1)
125 {
126  list($fileC, $funcC) = getPhpSourceCodePositionInfo(($backjumps - 1) + 1);
127  list($fileF, $funcF) = getPhpSourceCodePositionInfo(($backjumps) + 1);
128 
129  echo "<pre style=\"text-align:left;\">$fileC - $funcC\nIS CALLED FROM: $fileF - $funcF</pre>";
130 
131  // BH: php 5.3 seems to not flushing the output consequently so following redirects are still performed
132  // and the output of vd() would be lost in nirvana if we not flush the output manualy
133  flush();
134  ob_flush();
135 }
136 
145 function getPhpSourceCodePositionInfo($backjumps = 0)
146 {
147  $i = $backjumps;
148  $j = $backjumps + 1;
149 
150  $e = new Exception();
151  $trace = $e->getTrace();
152 
153  $file = basename($trace[$i]['file']) . ':' . $trace[$i]['line'];
154 
155  $func = '';
156 
157  if (isset($trace[$j]['class']) && strlen($trace[$j]['class'])) {
158  $func = $trace[$j]['class'];
159 
160  if (isset($trace[$j]['class']) && strlen($trace[$j]['class'])) {
161  $func .= $trace[$j]['type'];
162  } else {
163  $func .= '::';
164  }
165  }
166 
167  $func .= $trace[$j]['function'] . '()';
168 
169  return array($file, $func);
170 }
vd()
shortcut for var_dump with enhanced debug information
Definition: inc.debug.php:42
if($format !==null) $name
Definition: metadata.php:146
pr($var, $name='')
shortcut for print_r
Definition: inc.debug.php:95
getPhpSourceCodePositionInfo($backjumps=0)
returns an array containing function information from backtrace (the optional backjump param conrols ...
Definition: inc.debug.php:145
cf($backjumps=1)
prints an information about the function that called the function that invoked this function (the opt...
Definition: inc.debug.php:124
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file