FilterCodeCaller

Since v1.2016041701

Description

FilterCodeCaller is a data filter. It is a wrapper around FilterBacktrace. It converts FilterBacktrace's return value into a CodeCaller value object.

FilterCodeCaller was introduced for use in the UnsupportedType exception.

Public Interface

FilterCodeCaller has the following public interface:

use GanbaroDigital\ExceptionHelpers\V1\Callers\Values\CodeCaller;

class FilterCodeCaller
{
    /**
     * work out who has called a piece of code
     *
     * @param  array $backtrace
     *         the debug_backtrace() return value
     * @param  array $$filterList
     *         a list of namespaces and classes to skip over
     * @return CodeCaller
     */
    public function __invoke($backtrace, $$filterList = []);

    /**
     * work out who has called a piece of code
     *
     * @param  array $backtrace
     *         the debug_backtrace() return value
     * @param  array $$filterList
     *         a list of namespaces and classes to skip over
     * @return CodeCaller
     */
    public static function from($backtrace, $$filterList = []);
}

How To Use

FilterCodeCaller can be used as an object, or as a static class method.

// import first
use GanbaroDigital\ExceptionHelpers\V1\Callers\Filters\FilterCodeCaller;

// we need a stack trace
// use DEBUG_BACKTRACE_IGNORE_ARGS to keep the trace very small
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

// we need a list of namespaces to filter out
//
// this can be individual namespaces, or classnames
$filterList = [
    'GanbaroDigital\Reflection\V1\Checks',
    'GanbaroDigital\Reflection\V1\Requirements',
    FilterCodeCaller::class,
];

// to use as an object
$filter = new FilterCodeCaller;
$caller = $filter($trace, $filterList);

// to call statically
$caller = FilterCodeCaller::from($trace, $filterList);

Return Value

FilterCodeCaller returns a CodeCaller value object. This object will contain details about the first entry on the debug_backtrace() stack that passed filtering.

Notes

None at this time.

Changelog

v1.2016052501

See Also