Esempio n. 1
0
function patchMethod($function, $patch, PatchHandle $handle = null)
{
    if ($handle === null) {
        $handle = new PatchHandle();
    }
    list($class, $method, $instance) = Utils\interpretCallback($function);
    $patch = new MethodPatchDecorator($patch);
    $patch->superclass = $class;
    $patch->method = $method;
    $patch->instance = $instance;
    $reflection = new \ReflectionMethod($class, $method);
    $declaringClass = $reflection->getDeclaringClass();
    $class = $declaringClass->getName();
    if (Utils\traitsSupported()) {
        $aliases = $declaringClass->getTraitAliases();
        if (isset($aliases[$method])) {
            list($trait, $method) = explode("::", $aliases[$method]);
        }
    }
    $patches =& State::$patches[$class][$method];
    $offset = Utils\append($patches, array($patch, $handle));
    $handle->addReference($patches[$offset]);
    if (Utils\runningOnHHVM()) {
        patchOnHHVM("{$class}::{$method}", $patch, $handle);
    }
    return $handle;
}
Esempio n. 2
0
function connectMethod($function, callable $target, Handle $handle = null)
{
    $handle = $handle ?: new Handle();
    list($class, $method, $instance) = Utils\interpretCallable($function);
    $target = new Decorator($target);
    $target->superclass = $class;
    $target->method = $method;
    $target->instance = $instance;
    $reflection = new \ReflectionMethod($class, $method);
    $declaringClass = $reflection->getDeclaringClass();
    $class = $declaringClass->getName();
    if (!Utils\runningOnHHVM()) {
        $aliases = $declaringClass->getTraitAliases();
        if (isset($aliases[$method])) {
            list($trait, $method) = explode('::', $aliases[$method]);
        }
    }
    $routes =& State::$routes[$class][$method];
    $offset = Utils\append($routes, [$target, $handle]);
    $handle->addReference($routes[$offset]);
    if (Utils\runningOnHHVM()) {
        connectOnHHVM("{$class}::{$method}", $handle);
    }
    return $handle;
}