BackTrace.php
Go to the documentation of this file.00001 <?php
00018 class BackTrace
00019 {
00031 const SCOPE_FILE = "file";
00032
00046 const SCOPE_FUNCTION = "function";
00047
00061 const SCOPE_METHOD = "->";
00062
00076 const SCOPE_STATIC = "::";
00077
00089 private $aCurrent = array();
00090
00102 private $aStack = array();
00103
00114 private $iLevel = 0;
00115
00129 public function __construct( array $aStack = array() )
00130 {
00131 $this->aStack = count( $aStack ) === 0 ? debug_backtrace() : $aStack;
00132 $this->levelTop();
00133 }
00134
00146 public function explain()
00147 {
00148 return BackTraceExplain::perform( $this );
00149 }
00150
00162 public function getAll()
00163 {
00164 return $this->aStack;
00165 }
00166
00177 public function getArguments()
00178 {
00179 if ( array_key_exists( "args", $this->aCurrent ) === false )
00180 {
00181 return array();
00182 }
00183 return (array) $this->aCurrent["args"];
00184 }
00185
00198 public function getClass()
00199 {
00200 if ( array_key_exists( "class", $this->aCurrent ) === false )
00201 {
00202 return "";
00203 }
00204 return (string) $this->aCurrent["class"];
00205 }
00206
00217 public function getCurrent()
00218 {
00219 return $this->aCurrent;
00220 }
00221
00232 public function getFile( $bOnlyName = false )
00233 {
00234 if ( array_key_exists( "file", $this->aCurrent ) === false )
00235 {
00236 return "";
00237 }
00238 if ( $bOnlyName === true )
00239 {
00240 return basename( (string) $this->aCurrent["file"] );
00241 }
00242 return (string) $this->aCurrent["file"];
00243 }
00244
00257 public function getFunction()
00258 {
00259 if ( array_key_exists( "function", $this->aCurrent ) === false )
00260 {
00261 return "";
00262 }
00263 return (string) $this->aCurrent["function"];
00264 }
00265
00273 public function getLevel()
00274 {
00275 return $this->iLevel;
00276 }
00277
00287 public function getLine()
00288 {
00289 if ( array_key_exists( "line", $this->aCurrent ) === false )
00290 {
00291 return 0;
00292 }
00293 return (integer) $this->aCurrent["line"];
00294 }
00295
00314 public function getScope()
00315 {
00316 $sType = $this->getType();
00317 if ( $sType === "" )
00318 {
00319 $sType = $this->getFunction() === "" ? self::SCOPE_FILE : self::SCOPE_FUNCTION;
00320 }
00321 return $sType;
00322 }
00323
00335 public function getType()
00336 {
00337 if ( array_key_exists( "type", $this->aCurrent ) === false )
00338 {
00339 return "";
00340 }
00341 return (string) $this->aCurrent["type"];
00342 }
00343
00351 public function levelBottom()
00352 {
00353 $this->setLevel( count( $this->aStack ) - 1 );
00354 }
00355
00373 public function levelDown( $iDepth = 1, $bTry = false )
00374 {
00375 $iDepth = (integer) $iDepth;
00376 $bReturn = $this->setLevel( $this->iLevel + $iDepth );
00377 if ( $bReturn === false && $bTry === true )
00378 {
00379 $iDepth > 0 ? $this->levelTop() : $this->levelBottom();
00380 }
00381 return $bReturn;
00382 }
00383
00391 public function levelTop()
00392 {
00393 $this->setLevel( 0 );
00394 }
00395
00413 public function levelUp( $iDepth = 1, $bTry = false )
00414 {
00415 $iDepth = (integer) $iDepth;
00416 $bReturn = $this->setLevel( $this->iLevel - $iDepth );
00417 if ( $bReturn === false && $bTry === true )
00418 {
00419 $iDepth > 0 ? $this->levelBottom() : $this->levelTop();
00420 }
00421 return $bReturn;
00422 }
00423
00436 public function setLevel( $iLevel )
00437 {
00438 $iLevel = (integer) $iLevel;
00439 if ( array_key_exists( $iLevel, $this->aStack ) === true )
00440 {
00441 $this->iLevel = $iLevel;
00442 }
00443 $this->aCurrent = &$this->aStack[$this->iLevel];
00444 return $this->iLevel === $iLevel;
00445 }
00446 }