You are here

function migrate_get_last_caller in Migrate 6.2

Gets the last caller from a backtrace.

Parameters

$backtrace: A standard PHP backtrace.

Return value

An associative array with keys 'file', 'line' and 'function'.

1 call to migrate_get_last_caller()
migrate_decode_exception in includes/d7.inc
Decode an exception, especially to retrieve the correct caller.

File

includes/d7.inc, line 101
Drupal 7 functions 'n' things implemented in Drupal 6, to ease backporting

Code

function migrate_get_last_caller($backtrace) {

  // Errors that occur inside PHP internal functions do not generate
  // information about file and line. Ignore black listed functions.
  $blacklist = array(
    'debug',
  );
  while ($backtrace && !isset($backtrace[0]['line']) || isset($backtrace[1]['function']) && in_array($backtrace[1]['function'], $blacklist)) {
    array_shift($backtrace);
  }

  // The first trace is the call itself.
  // It gives us the line and the file of the last call.
  $call = $backtrace[0];

  // The second call give us the function where the call originated.
  if (isset($backtrace[1])) {
    if (isset($backtrace[1]['class'])) {
      $call['function'] = $backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . '()';
    }
    else {
      $call['function'] = $backtrace[1]['function'] . '()';
    }
  }
  else {
    $call['function'] = 'main()';
  }
  return $call;
}