diff --git a/src/CallRerouting.php b/src/CallRerouting.php index 60b9679..c1fbff9 100644 --- a/src/CallRerouting.php +++ b/src/CallRerouting.php @@ -181,7 +181,7 @@ function inPreprocessedFile($callable) function connectFunction($function, callable $target, ?Handle $handle = null) { $handle = $handle ?: new Handle; - $routes = &State::$routes[null][$function]; + $routes = &State::$routes[''][$function]; $offset = Utils\append($routes, [$target, $handle]); $handle->addReference($routes[$offset]); return $handle; @@ -311,6 +311,10 @@ function dispatch($class, $calledClass, $method, $frame, &$result, ?array $args function relay(?array $args = null) { list($class, $method, $offset) = end(State::$routeStack); + $class = $class ?? ''; + $method = $method ?? ''; + $offset = $offset ?? ''; + $route = &State::$routes[$class][$method][$offset]; $backup = $route; $route = ['Patchwork\fallBack', new Handle]; @@ -387,6 +391,9 @@ function getHHVMExpirationHandler($function) function getRoutesFor($class, $method) { + $class = $class ?? ''; + $method = $method ?? ''; + if (!isset(State::$routes[$class][$method])) { return []; } @@ -431,7 +438,7 @@ function createStubsForInternals() '$__pwRefOffset = 0;', '$__pwRefOffset = 1;', \Patchwork\CodeManipulation\Actions\CallRerouting\CALL_INTERCEPTION_CODE - ), + ), $refs ); eval(strtr(INTERNAL_STUB_CODE, [ diff --git a/src/CodeManipulation/Actions/CallRerouting.php b/src/CodeManipulation/Actions/CallRerouting.php index e5059c3..f876ddc 100644 --- a/src/CodeManipulation/Actions/CallRerouting.php +++ b/src/CodeManipulation/Actions/CallRerouting.php @@ -14,7 +14,7 @@ const CALL_INTERCEPTION_CODE = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ""; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0)); @@ -29,7 +29,7 @@ const CALL_INTERCEPTION_CODE_VOID_TYPED = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ""; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0)); @@ -47,7 +47,7 @@ const CALL_INTERCEPTION_CODE_NEVER_TYPED = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ""; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0));