コード例 #1
0
ファイル: yTest_RewireMethod.php プロジェクト: rsaugier/ytest
 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();
 }
コード例 #2
0
 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();
 }
コード例 #3
0
 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);
     }
 }
コード例 #4
0
 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);
 }
コード例 #5
0
ファイル: yTest_CodeGen.php プロジェクト: rsaugier/ytest
 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;
 }
コード例 #6
0
ファイル: yTest_CallsRouter.php プロジェクト: rsaugier/ytest
 public function onFunctionRewire($functionName, $delegateObject)
 {
     yTest_debugCC("onFunctionRewire {$functionName}");
     $this->funcNameToDelegate[$functionName] = $delegateObject;
 }
コード例 #7
0
ファイル: yTest_Reflection.php プロジェクト: rsaugier/ytest
 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);
 }