コード例 #1
0
ファイル: Proxy.php プロジェクト: sibenye/naijaskillhub
 protected static function checkCalledMethod($constant)
 {
     $trace = debug_backtrace();
     $info = Backtrace::getInfo('ConstantPatcher', $trace);
     $class = strtolower($info['class']);
     $class_method = strtolower($info['class_method']);
     // Patches the constants only in the class
     if (strpos(self::$patches_to_apply[$constant], '::') === false) {
         if (self::$patches_to_apply[$constant] !== $class) {
             return false;
         }
         return true;
     } else {
         if (self::$patches_to_apply[$constant] !== $class_method) {
             return false;
         }
         return true;
     }
 }
コード例 #2
0
 public static function getReturn($class, $method, $params)
 {
     if (MonkeyPatchManager::$debug) {
         $trace = debug_backtrace();
         $info = Backtrace::getInfo('MethodPatcher', $trace);
         $file = $info['file'];
         $line = $info['line'];
         if (isset($info['class_method'])) {
             $called_method = $info['class_method'];
         } elseif (isset($info['function'])) {
             $called_method = $info['function'];
         } else {
             $called_method = 'n/a';
         }
         $log_args = function () use($params) {
             $output = '';
             foreach ($params as $arg) {
                 $output .= var_export($arg, true) . ', ';
             }
             $output = rtrim($output, ', ');
             return $output;
         };
         MonkeyPatchManager::log('invoke_method: ' . $class . '::' . $method . '(' . $log_args() . ') on line ' . $line . ' in ' . $file . ' by ' . $called_method);
         //			var_dump($trace); exit;
     }
     self::$invocations[$class . '::' . $method][] = $params;
     if (isset(self::$patches[$class]) && array_key_exists($method, self::$patches[$class])) {
         $patch = self::$patches[$class][$method];
     } else {
         return __GO_TO_ORIG__;
     }
     if (is_callable($patch)) {
         return call_user_func_array($patch, $params);
     } else {
         return $patch;
     }
 }
コード例 #3
0
ファイル: Proxy.php プロジェクト: yutayokoi/CodeIgniter
 protected static function checkPassedByReference($function)
 {
     $ref_func = new ReflectionFunction($function);
     foreach ($ref_func->getParameters() as $param) {
         if ($param->isPassedByReference()) {
             // Add tmp blacklist
             Cache::appendTmpFunctionBlacklist($function);
             // Remove cache file
             $backtrace = debug_backtrace();
             $info = Backtrace::getInfo('FunctionPatcher', $backtrace);
             $orig_file = $info['file'];
             $cache = Cache::removeSrcCacheFile($orig_file);
             $pr_msg = '';
             if (self::isInternalFunction($function)) {
                 $pr_msg = "<red>Please send Pull Request to add function '{$function}' to default config.</red>\n";
             }
             $tmp_blacklist_file = Cache::getTmpFunctionBlacklistFile();
             $msg = "\n" . "<red>Can't patch on function '{$function}'.</red>\n" . "It has param(s) passed by reference.\n" . "Added it temporary blacklist file '{$tmp_blacklist_file}'.\n" . "And removed cache file '{$cache}'.\n" . "{$pr_msg}" . "\n<red>Please run phpunit again.</red>";
             self::outputMessage($msg);
             throw new LogicException($msg);
         }
     }
 }