Beispiel #1
0
 public function apply()
 {
     $params = yTest_Signature::getParamsDecl($this->methodName, $this->className);
     if (yTest_Reflection::isStaticMethod($this->className, $this->methodName)) {
         $code = '$x = yTest_CallsRouter::$singleton->getDelegateObjectForStaticMethod("' . $this->className . '", "' . $this->methodName . '");' . "\n";
         $code .= 'return $x->' . $this->delegateMethodName . '(' . yTest_Signature::getArgsForSimpleCall($this->methodName, $this->className) . ');';
         yTest_CallsRouter::$singleton->onClassMethodRewire($this->className, $this->methodName, $this->delegateObject);
     } else {
         $code = 'global $yTest__orig_instance; $yTest__orig_instance = $this;' . "\n";
         $code .= '$x = yTest_CallsRouter::$singleton->getDelegateObjectForInstanceMethod($this, "' . $this->methodName . '");' . "\n";
         $code .= 'if($x === null) {' . "\n";
         $code .= '    return $this->' . yTest_Reflection::getOriginalMethodName($this->methodName) . '(' . yTest_Signature::getArgsForSimpleCall($this->methodName, $this->className) . ');' . "\n";
         $code .= "}\n";
         $code .= "else {\n";
         $code .= '    return $x->' . $this->delegateMethodName . '(' . yTest_Signature::getArgsForSimpleCall($this->methodName, $this->className) . ');' . "\n";
         $code .= "}\n";
         switch ($this->rewireMode) {
             case self::REWIRE_MODE_FOR_ALL_INSTANCES:
                 yTest_CallsRouter::$singleton->onClassMethodRewire($this->className, $this->methodName, $this->delegateObject);
                 break;
             case self::REWIRE_MODE_FOR_SPECIFIC_INSTANCE:
                 yTest_CallsRouter::$singleton->onInstanceMethodRewire($this->instance, $this->methodName, $this->delegateObject);
                 break;
             default:
                 yTest_error("invalid rewireMode");
                 break;
         }
     }
     yTest_debugCC("PARAMS: {$params}", "CODE: {$code}");
     $flags = yTest_Reflection::getRunkitMethodFlags($this->className, $this->methodName);
     yTest_Reflection::replaceMethod($this->className, $this->methodName, $params, $code, $flags);
     //yTest_CallsRouter::instance()->dump();
 }
 public function apply()
 {
     if (method_exists($this->className, yTest_Reflection::getOriginalMethodName($this->methodName))) {
         throw new yTest_Exception('trying to create public delegate (letMeCall) on the already rewired method ' . $this->className . '::' . $this->methodName);
     }
     $params = yTest_Signature::getParamsDecl($this->methodName, $this->className);
     $runkitFlags = RUNKIT_ACC_PUBLIC;
     if (yTest_Reflection::isStaticMethod($this->className, $this->methodName)) {
         $code = 'return self::' . $this->methodName . '(' . yTest_Signature::getArgsForSimpleCall($this->methodName, $this->className) . ');';
         $runkitFlags |= RUNKIT_ACC_STATIC;
     } else {
         $code = 'return $this->' . $this->methodName . '(' . yTest_Signature::getArgsForSimpleCall($this->methodName, $this->className) . ');';
     }
     yTest_debugCC("PARAMS: {$params}", "CODE: {$code}");
     runkit_method_add($this->className, $this->delegateName, $params, $code, $runkitFlags);
 }