Ejemplo n.º 1
0
function dispatch($class, $calledClass, $method, $frame, &$result, array $args = null)
{
    $success = false;
    Stack\pushFor($frame, $calledClass, function () use($class, $method, &$result, &$success) {
        foreach (getRoutesFor($class, $method) as $offset => $route) {
            if (empty($route)) {
                unset(State::$routes[$class][$method][$offset]);
                continue;
            }
            State::$routeStack[] = [$class, $method, $offset];
            try {
                $result = dispatchTo(reset($route));
                $success = true;
            } catch (Exceptions\NoResult $e) {
                array_pop(State::$routeStack);
                continue;
            }
            array_pop(State::$routeStack);
            if ($success) {
                break;
            }
        }
    }, $args);
    return $success;
}
Ejemplo n.º 2
0
function intercept($class, $calledClass, $method, $frame, &$result, array $args = null)
{
    $success = false;
    Stack\pushFor($frame, $calledClass, function () use($class, $method, &$result, &$success) {
        foreach (State::$patches[$class][$method] as $offset => $patch) {
            if (empty($patch)) {
                unset(State::$patches[$class][$method][$offset]);
                continue;
            }
            State::$patchStack[] = array($class, $method, $offset);
            try {
                $result = runPatch(reset($patch));
                $success = true;
            } catch (Exceptions\NoResult $e) {
                array_pop(State::$patchStack);
                continue;
            }
            array_pop(State::$patchStack);
        }
    }, $args);
    return $success;
}
Ejemplo n.º 3
0
function dispatch($class, $calledClass, $method, $frame, &$result, array $args = null)
{
    if (strpos($method, INTERNAL_REDEFINITION_NAMESPACE) === 0 && $args === null) {
        # Mind the namespace-of-origin argument
        $trace = debug_backtrace();
        $args = array_reverse($trace)[$frame - 1]['args'];
        array_shift($args);
    }
    $success = false;
    Stack\pushFor($frame, $calledClass, function () use($class, $method, &$result, &$success) {
        foreach (getRoutesFor($class, $method) as $offset => $route) {
            if (empty($route)) {
                unset(State::$routes[$class][$method][$offset]);
                continue;
            }
            State::$routeStack[] = [$class, $method, $offset];
            try {
                $result = dispatchTo(reset($route));
                $success = true;
            } catch (Exceptions\NoResult $e) {
                array_pop(State::$routeStack);
                continue;
            }
            array_pop(State::$routeStack);
            if ($success) {
                break;
            }
        }
    }, $args);
    return $success;
}