ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  {
50  return false;
51  }
52 
53  $arg_list = func_get_args();
54  $num = 1;
55 
56  include_once 'Services/Authentication/classes/class.ilAuthFactory.php';
58  $cli = true;
59  else $cli = false;
60 
61  foreach ($arg_list as $arg)
62  {
63  if(!$cli)
64  {
65  $printbefore = "<pre style=\"text-align:left;\">";
66  $printbefore .= "$file - $func - variable $num:<br/>";
67  $printafter = "</pre><br/>";
68  }
69  else
70  {
71  $printbefore = "\n\n_________________________________________________".
72  "_________________________________________________\n";
73  $printbefore .= "$file - $func - variable $num:\n\n";
74  $printafter = "_________________________________________________".
75  "_________________________________________________\n\n";
76  }
77 
78  echo $printbefore;
79  var_dump($arg);
80  echo $printafter;
81  $num++;
82  }
83 
84  // BH: php 5.3 seems to not flushing the output consequently so following redirects are still performed
85  // and the output of vd() would be lost in nirvana if we not flush the output manualy
86  flush(); ob_flush();
87 }
88 
97 function pr($var,$name = '')
98 {
99  if($name != '') $name .= ' = ';
100  $print = $name.print_r($var,true);
101 
103  {
104  $hr = "\n---------------------------------------------------------------\n";
105  echo $hr.$print.$hr;
106  }
107  else
108  {
109  echo '<pre>'.$print.'</pre>';
110  }
111 
112  // BH: php 5.3 seems to not flushing the output consequently so following redirects are still performed
113  // and the output of vd() would be lost in nirvana if we not flush the output manualy
114  flush(); ob_flush();
115 }
116 
126 function cf($backjumps = 1)
127 {
128  list($fileC, $funcC) = getPhpSourceCodePositionInfo( ($backjumps - 1) + 1 );
129  list($fileF, $funcF) = getPhpSourceCodePositionInfo( ($backjumps) + 1 );
130 
131  echo "<pre style=\"text-align:left;\">$fileC - $funcC\nIS CALLED FROM: $fileF - $funcF</pre>";
132 
133  // BH: php 5.3 seems to not flushing the output consequently so following redirects are still performed
134  // and the output of vd() would be lost in nirvana if we not flush the output manualy
135  flush(); ob_flush();
136 }
137 
146 function getPhpSourceCodePositionInfo($backjumps = 0)
147 {
148  $i = $backjumps;
149  $j = $backjumps + 1;
150 
151  $e = new Exception();
152  $trace = $e->getTrace();
153 
154  $file = basename($trace[$i]['file']).':'.$trace[$i]['line'];
155 
156  $func = '';
157 
158  if( isset($trace[$j]['class']) && strlen($trace[$j]['class']) )
159  {
160  $func = $trace[$j]['class'];
161 
162  if( isset($trace[$j]['class']) && strlen($trace[$j]['class']) )
163  $func .= $trace[$j]['type'];
164  else $func .= '::';
165  }
166 
167  $func .= $trace[$j]['function'].'()';
168 
169  return array($file, $func);
170 }