Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/CallRerouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -387,6 +391,9 @@ function getHHVMExpirationHandler($function)

function getRoutesFor($class, $method)
{
$class = $class ?? '';
$method = $method ?? '';

if (!isset(State::$routes[$class][$method])) {
return [];
}
Expand Down Expand Up @@ -431,7 +438,7 @@ function createStubsForInternals()
'$__pwRefOffset = 0;',
'$__pwRefOffset = 1;',
\Patchwork\CodeManipulation\Actions\CallRerouting\CALL_INTERCEPTION_CODE
),
),
$refs
);
eval(strtr(INTERNAL_STUB_CODE, [
Expand Down
6 changes: 3 additions & 3 deletions src/CodeManipulation/Actions/CallRerouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down