lithium\analysis\Debugger::_closureDef()

protected static method

Helper method for caching closure function references to help the process of building the stack trace.

Parameters

  • array $frame

    Backtrace information.

  • callable|string $function

    The method related to $frame information.

Returns

string

Returns either the cached or the fetched closure function reference while writing its reference to the cache array $_closureCache.

Source

	protected static function _closureDef($frame, $function) {
		$reference = '::';
		$frame += ['file' => '??', 'line' => '??'];
		$cacheKey = "{$frame['file']}@{$frame['line']}";

		if (isset(static::$_closureCache[$cacheKey])) {
			return static::$_closureCache[$cacheKey];
		}

		if ($class = Inspector::classes(['file' => $frame['file']])) {
			foreach (Inspector::methods(key($class), 'extents') as $method => $extents) {
				$line = $frame['line'];

				if (!($extents[0] <= $line && $line <= $extents[1])) {
					continue;
				}
				$class = key($class);
				$reference = "{$class}::{$method}";
				$function = "{$reference}()::{closure}";
				break;
			}
		} else {
			$reference = $frame['file'];
			$function = "{$reference}::{closure}";
		}
		$line = static::_definition($reference, $frame['line']) ?: '?';
		$function .= " @ {$line}";
		return static::$_closureCache[$cacheKey] = $function;
	}