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() { $params = yTest_Signature::getParamsDecl($this->functionName); $code = '$x = yTest_CallsRouter::$singleton->getDelegateObjectForFunction("' . $this->functionName . '");' . "\n"; $code .= 'return $x->' . $this->delegateMethodName . '(' . yTest_Signature::getArgsForSimpleCall($this->functionName) . ');'; yTest_CallsRouter::$singleton->onFunctionRewire($this->functionName, $this->delegateObject); yTest_debugCC("PARAMS: {$params}", "CODE: {$code}"); yTest_Reflection::replaceFunction($this->functionName, $params, $code); //yTest_CallsRouter::instance()->dump(); }
private function setValue(&$val) { yTest_debugCC('setValue ' . $this->className . '::' . $this->propertyName . ' = ' . var_export($val, true)); if ($this->isPublic) { $refl = new ReflectionClass($this->className); $refl->setStaticPropertyValue($this->propertyName, $val); } else { call_user_func(array($this->className, yTest_AddPublicAccessors::getSetterName($this->className, $this->propertyName)), $val); } }
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); }
public static function genClassWithSingleFuncStub($funcOrStaticMethodName, $staticMethodClassName = null) { $newClassName = self::COMMON_PREFIX . self::CLASS_WITH_SINGLE_FUNC_STUB_PREFIX; if ($staticMethodClassName !== null) { $newClassName .= $staticMethodClassName . '_'; } $newClassName .= $funcOrStaticMethodName; if (class_exists($newClassName, false)) { yTest_debugCC("ALREADY GEN'd: {$newClassName}"); } else { $code = 'class ' . $newClassName . ' {' . "\n"; $code .= ' public function ' . $funcOrStaticMethodName . '(' . yTest_Signature::getParamsDecl($funcOrStaticMethodName, $staticMethodClassName) . ') {}' . "\n"; $code .= "}\n"; yTest_debugCC("CODE: {$code}"); eval($code); } return $newClassName; }
public function onFunctionRewire($functionName, $delegateObject) { yTest_debugCC("onFunctionRewire {$functionName}"); $this->funcNameToDelegate[$functionName] = $delegateObject; }
public static function redefineConstant($className, $constName, $value) { $runkitName = ($className === null ? "" : $className . "::") . $constName; yTest_debugCC("redefineConstant {$runkitName} to value " . var_export($value, true)); $res = runkit_constant_redefine($runkitName, $value); yTest_assert($res); }