当前位置: 首页>>代码示例>>PHP>>正文


PHP runkit_function_redefine函数代码示例

本文整理汇总了PHP中runkit_function_redefine函数的典型用法代码示例。如果您正苦于以下问题:PHP runkit_function_redefine函数的具体用法?PHP runkit_function_redefine怎么用?PHP runkit_function_redefine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了runkit_function_redefine函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: redefineFunction

 /**
  * @param RunkitFunction $function
  *
  * @return boolean
  */
 public function redefineFunction(\Runkit\RunkitFunction $function)
 {
     if (!function_exists('runkit_function_redefine')) {
         return false;
     }
     return runkit_function_redefine($function->getName(), (string) $function->getArguments(), $function->getCode()->get());
 }
开发者ID:oncesk,项目名称:runkit,代码行数:12,代码来源:Executor.php

示例2: logFunc

 function logFunc($name)
 {
     // copy function to fuinction_o
     runkit_function_copy($name, $name . "_o");
     // runkit_function_redefine($name,"","logger_simple(); if(!empty(getargs())) return {$name}_o(getargs()); else return {$name}_o();");
     // redefine function and internally call the original function (function_o)
     runkit_function_redefine($name, "", "return logger();");
 }
开发者ID:DanielRuf,项目名称:honeypot-scripts,代码行数:8,代码来源:logger.php

示例3: _wpe_replace_function

 function _wpe_replace_function($name, $args)
 {
     if (function_exists($name)) {
         // is possible that it doesn't!  Then don't emit errors.
         $call_args = preg_replace("#=[^,]+#", "", $args);
         runkit_function_copy($name, "_wpe_old_{$name}");
         runkit_function_redefine($name, $args, "return _wpe_new_{$name}({$call_args});");
     }
 }
开发者ID:tconte252,项目名称:haute-inhabit,代码行数:9,代码来源:preamble.php

示例4: timeInit

 public static function timeInit()
 {
     if (!isset(self::$_timeStart)) {
         runkit_function_copy('time', 'time_original');
         runkit_function_redefine('time', '', 'return CMTest_TH::time();');
     }
     self::$_timeStart = time_original();
     self::$timeDelta = 0;
 }
开发者ID:aladin1394,项目名称:CM,代码行数:9,代码来源:TH.php

示例5: runkitOverride

 /**
  * Override function
  *
  * @param string $func
  * @param string $args
  * @param string $body
  * @param mixed $mock
  */
 protected function runkitOverride($func, $args, $body, $mock = null)
 {
     $this->skipTestIfNoRunkit();
     if (array_key_exists($func, self::$override_functions)) {
         throw new \RuntimeException("Function '{$func}' is marked as mocked already");
     }
     self::$override_functions[$func] = $mock;
     \runkit_function_copy($func, $func . self::BACKUP_SUFFIX);
     \runkit_function_redefine($func, $args, $body);
 }
开发者ID:rtutin,项目名称:sendmail,代码行数:18,代码来源:RunkitTestCase.php

示例6: setUpSuccess

 /**
  * Testcase Constructor for successful request.
  *
  * @return void
  */
 public function setUpSuccess()
 {
     if (extension_loaded('curl') === FALSE) {
         $this->markTestSkipped('Extension curl is required.');
     }
     if (extension_loaded('runkit') === FALSE) {
         $this->markTestSkipped('Extension runkit is required.');
     }
     runkit_function_redefine('curl_errno', '', self::CURL_RETURN_ERRNO);
     runkit_function_redefine('curl_error', '', self::CURL_RETURN_ERRMSG);
     runkit_function_redefine('curl_getinfo', '', self::CURL_RETURN_INFO);
     $this->class = new CurlResponse('Result', 'handle');
     $this->reflection = new ReflectionClass('Lunr\\Network\\CurlResponse');
 }
开发者ID:rubendgr,项目名称:lunr,代码行数:19,代码来源:CurlResponseTest.php

示例7: __construct

 public function __construct($functionName)
 {
     $this->functionName = $functionName;
     if (function_exists($functionName)) {
         if (!function_exists('runkit_function_redefine')) {
             throw new Exception("PECL runkit extension is required to override functions. see http://www.php.net/manual/en/runkit.installation.php for more info.");
         }
         $rf = new ReflectionFunction($functionName);
         $rp = $rf->getParameters();
         $aParams = array();
         foreach ($rp as $param) {
             $aParams[] = '$' . $param;
         }
         $fnc_code = '$mock = PHPMockFunction::getMock(\'' . $functionName . '\');' . "\n" . 'return $mock->invoke(func_get_args());';
         runkit_function_redefine(strtolower($functionName), '', $fnc_code);
     } else {
         eval("function {$functionName}() {\n                    return PHPMockFunction::getMock('{$functionName}')->invoke(func_get_args());\n                }");
     }
 }
开发者ID:rollinsb1010,项目名称:elearning,代码行数:19,代码来源:PHPMockFunction.php

示例8: testMysqlDBI

 /**
  * Test for mysql related functions, using runkit_function_redefine
  *
  * @return void
  *
  * @group medium
  */
 public function testMysqlDBI()
 {
     if (!PMA_HAS_RUNKIT) {
         $this->markTestSkipped("Cannot redefine function");
     }
     //FOR UT, we just test the right mysql client API is called
     runkit_function_redefine('mysql_pconnect', '', 'return "mysql_pconnect";');
     runkit_function_redefine('mysql_connect', '', 'return "mysql_connect";');
     runkit_function_redefine('mysql_query', '', 'return "mysql_query";');
     runkit_function_redefine('mysql_fetch_array', '', 'return "mysql_fetch_array";');
     runkit_function_redefine('mysql_data_seek', '', 'return "mysql_data_seek";');
     runkit_function_redefine('mysql_get_host_info', '', 'return "mysql_get_host_info";');
     runkit_function_redefine('mysql_get_proto_info', '', 'return "mysql_get_proto_info";');
     runkit_function_redefine('mysql_field_flags', '', 'return "mysql_field_flags";');
     runkit_function_redefine('mysql_field_name', '', 'return "mysql_field_name";');
     runkit_function_redefine('mysql_field_len', '', 'return "mysql_field_len";');
     runkit_function_redefine('mysql_num_fields', '', 'return "mysql_num_fields";');
     runkit_function_redefine('mysql_affected_rows', '', 'return "mysql_affected_rows";');
     //test for fieldFlags
     $result = array("table1", "table2");
     $ret = $this->object->numFields($result);
     $this->assertEquals('mysql_num_fields', $ret);
     //test for fetchRow
     $result = array("table1", "table2");
     $ret = $this->object->fetchRow($result);
     $this->assertEquals('mysql_fetch_array', $ret);
     //test for fetchRow
     $result = array("table1", "table2");
     $ret = $this->object->fetchAssoc($result);
     $this->assertEquals('mysql_fetch_array', $ret);
     //test for affectedRows
     $link = "PMA_link";
     $get_from_cache = false;
     $ret = $this->object->affectedRows($link, $get_from_cache);
     $this->assertEquals("mysql_affected_rows", $ret);
     //test for connect
     $user = 'PMA_user';
     $password = 'PMA_password';
     $is_controluser = false;
     $server = array('port' => 8080, 'socket' => 123, 'host' => 'locahost');
     $auxiliary_connection = true;
     //test for connect
     $ret = $this->object->connect($user, $password, $is_controluser, $server, $auxiliary_connection);
     $this->assertEquals('mysql_connect', $ret);
     $GLOBALS['cfg']['PersistentConnections'] = true;
     $ret = $this->object->connect($user, $password, $is_controluser, $server, $auxiliary_connection);
     $this->assertEquals('mysql_pconnect', $ret);
     //test for realQuery
     $query = 'select * from DBI';
     $link = $ret;
     $options = 0;
     $ret = $this->object->realQuery($query, $link, $options);
     $this->assertEquals('mysql_query', $ret);
     //test for fetchArray
     $result = $ret;
     $ret = $this->object->fetchArray($result);
     $this->assertEquals('mysql_fetch_array', $ret);
     //test for dataSeek
     $result = $ret;
     $offset = 12;
     $ret = $this->object->dataSeek($result, $offset);
     $this->assertEquals('mysql_data_seek', $ret);
     //test for getHostInfo
     $ret = $this->object->getHostInfo($ret);
     $this->assertEquals('mysql_get_host_info', $ret);
     //test for getProtoInfo
     $ret = $this->object->getProtoInfo($ret);
     $this->assertEquals('mysql_get_proto_info', $ret);
     //test for fieldLen
     $ret = $this->object->fieldLen($ret, $offset);
     $this->assertEquals('mysql_field_len', $ret);
     //test for fieldName
     $ret = $this->object->fieldName($ret, $offset);
     $this->assertEquals('mysql_field_name', $ret);
     //test for fieldFlags
     $ret = $this->object->fieldFlags($ret, $offset);
     $this->assertEquals('mysql_field_flags', $ret);
 }
开发者ID:kfjihailong,项目名称:phpMyAdmin,代码行数:85,代码来源:DBIMysql_test.php

示例9: generate_data


//.........这里部分代码省略.........
     foreach ($fields as $key => $field) {
         // rename programs field ##
         if ($field == 'member_of_club') {
             $field = 'Program';
         }
         // grab fields to exclude from exports ##
         if (in_array($field, $this->get_exclude_fields())) {
             // ditch 'em ##
             unset($fields[$key]);
         } else {
             if ($is_csv) {
                 $headers[] = '"' . $field . '"';
             } else {
                 $headers[] = $field;
                 #echo '<script>console.log("Echoing header cell: '.$field.'")</script>';
             }
         }
     }
     // quick check ##
     #if ( self::debug ) self::log( 'All Fields: '. var_dump( $fields ) );
     #if ( self::debug ) self::log( '$bp_fields_passed: '. var_dump( $bp_fields_passed ) );
     // no more buffering while spitting back the export data ##
     ob_end_flush();
     // get the value in bytes allocated for Memory via php.ini ##
     // @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue
     $memory_limit = $this->return_bytes(ini_get('memory_limit')) * 0.75;
     // we need to disable caching while exporting because we export so much data that it could blow the memory cache
     // if we can't override the cache here, we'll have to clear it later...
     if (function_exists('override_function')) {
         override_function('wp_cache_add', '$key, $data, $group="", $expire=0', '');
         override_function('wp_cache_set', '$key, $data, $group="", $expire=0', '');
         override_function('wp_cache_replace', '$key, $data, $group="", $expire=0', '');
         override_function('wp_cache_add_non_persistent_groups', '$key, $data, $group="", $expire=0', '');
     } elseif (function_exists('runkit_function_redefine')) {
         runkit_function_redefine('wp_cache_add', '$key, $data, $group="", $expire=0', '');
         runkit_function_redefine('wp_cache_set', '$key, $data, $group="", $expire=0', '');
         runkit_function_redefine('wp_cache_replace', '$key, $data, $group="", $expire=0', '');
         runkit_function_redefine('wp_cache_add_non_persistent_groups', '$key, $data, $group="", $expire=0', '');
     }
     // open doc wrapper.. ##
     echo $doc_begin;
     // echo headers ##
     echo $pre . implode($seperator, $headers) . $breaker;
     #wp_die( self::pr( $users ) );
     // build row values for each user ##
     foreach ($users as $user) {
         #wp_die( self::pr( $user ) );
         // check if we're hitting any Memory limits, if so flush them out ##
         // per http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
         if (memory_get_usage(true) > $memory_limit) {
             wp_cache_flush();
         }
         // open up a new empty array ##
         $data = array();
         #wp_die( self::pr( $GLOBALS['bp'] ) );
         // BP loaded ? ##
         if (function_exists('bp_is_active') && bp_is_active('xprofile')) {
             // grab all user data ##
             $bp_data = BP_XProfile_ProfileData::get_all_for_user($user->ID);
         }
         // single query method - get all user_meta data ##
         $get_user_meta = (array) get_user_meta($user->ID);
         #wp_die( self::pr( $get_user_meta ) );
         // Filter out empty meta data ##
         #$get_user_meta = array_filter( array_map( function( $a ) {
         #    return $a[0];
开发者ID:adnandot,项目名称:intenseburn,代码行数:67,代码来源:export-user-data.php

示例10: generate_data


//.........这里部分代码省略.........
     $data_keys = array('ID', 'user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'display_name');
     // compile final fields list ##
     $fields = array_merge($data_keys, $usermeta_fields, $bp_fields_passed, $bp_fields_update_passed);
     // build the document headers ##
     $headers = array();
     foreach ($fields as $key => $field) {
         // rename programs field ##
         if ($field == 'member_of_club') {
             $field = 'Program';
         }
         if (in_array($field, $exclude_data)) {
             unset($fields[$key]);
         } else {
             if ($is_csv) {
                 $headers[] = '"' . $field . '"';
             } else {
                 $headers[] = $field;
                 #echo '<script>console.log("Echoing header cell: '.$field.'")</script>';
             }
         }
     }
     // no more buffering while spitting back the export data ##
     ob_end_flush();
     // get the value in bytes allocated for Memory via php.ini ##
     // @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
     $memory_limit = $this->return_bytes(ini_get('memory_limit')) * 0.75;
     // we need to disable caching while exporting because we export so much data that it could blow the memory cache
     // if we can't override the cache here, we'll have to clear it later...
     if (function_exists('override_function')) {
         override_function('wp_cache_add', '$key, $data, $group="", $expire=0', '');
         override_function('wp_cache_set', '$key, $data, $group="", $expire=0', '');
         override_function('wp_cache_replace', '$key, $data, $group="", $expire=0', '');
         override_function('wp_cache_add_non_persistent_groups', '$key, $data, $group="", $expire=0', '');
     } elseif (function_exists('runkit_function_redefine')) {
         runkit_function_redefine('wp_cache_add', '$key, $data, $group="", $expire=0', '');
         runkit_function_redefine('wp_cache_set', '$key, $data, $group="", $expire=0', '');
         runkit_function_redefine('wp_cache_replace', '$key, $data, $group="", $expire=0', '');
         runkit_function_redefine('wp_cache_add_non_persistent_groups', '$key, $data, $group="", $expire=0', '');
     }
     // open doc wrapper.. ##
     echo $doc_begin;
     // echo headers ##
     echo $pre . implode($seperator, $headers) . $breaker;
     // build row values for each user ##
     foreach ($users as $user) {
         // check if we're hitting any Memory limits, if so flush them out ##
         // per http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
         if (memory_get_usage(true) > $memory_limit) {
             wp_cache_flush();
         }
         // open up a new empty array ##
         $data = array();
         // BP loaded ? ##
         if (function_exists('bp_is_active')) {
             $bp_data = BP_XProfile_ProfileData::get_all_for_user($user->ID);
         }
         // loop over each field ##
         foreach ($fields as $field) {
             // check if this is a BP field ##
             if (isset($bp_data) && isset($bp_data[$field]) && in_array($field, $bp_fields_passed)) {
                 $value = $bp_data[$field];
                 if (is_array($value)) {
                     $value = maybe_unserialize($value['field_data']);
                     // suggested by @grexican ##
                     #$value = $value['field_data'];
                     /**
开发者ID:grexican,项目名称:export-user-data,代码行数:67,代码来源:export-user-data.php

示例11: overrideNativeFuncs

 /**
  * Overrides native PHP functions.
  * @return void
  */
 protected function overrideNativeFuncs()
 {
     if (Daemon::supported(Daemon::SUPPORT_RUNKIT_INTERNAL_MODIFY)) {
         function define($k, $v)
         {
             if (defined($k)) {
                 runkit_constant_redefine($k, $v);
             } else {
                 runkit_constant_add($k, $v);
             }
         }
         $this->override('define');
         function header()
         {
             if (!Daemon::$context instanceof \PHPDaemon\Request\Generic) {
                 return false;
             }
             return call_user_func_array([Daemon::$context, 'header'], func_get_args());
         }
         $this->override('header');
         function is_uploaded_file()
         {
             if (!Daemon::$context instanceof \PHPDaemon\Request\Generic) {
                 return false;
             }
             return call_user_func_array([Daemon::$context, 'isUploadedFile'], func_get_args());
         }
         $this->override('is_uploaded_file');
         function move_uploaded_file()
         {
             if (!Daemon::$context instanceof \PHPDaemon\Request\Generic) {
                 return false;
             }
             return call_user_func_array([Daemon::$context, 'moveUploadedFile'], func_get_args());
         }
         $this->override('move_uploaded_file');
         function headers_sent(&$file = null, &$line = null)
         {
             if (!Daemon::$context instanceof \PHPDaemon\Request\Generic) {
                 return false;
             }
             return Daemon::$context->headers_sent($file, $line);
         }
         //$this->override('headers_sent');
         function headers_list()
         {
             if (!Daemon::$context instanceof \PHPDaemon\Request\Generic) {
                 return false;
             }
             return Daemon::$context->headers_list();
         }
         $this->override('headers_list');
         function setcookie()
         {
             if (!Daemon::$context instanceof \PHPDaemon\Request\Generic) {
                 return false;
             }
             return call_user_func_array([Daemon::$context, 'setcookie'], func_get_args());
         }
         $this->override('setcookie');
         /**
          * @param callable $cb
          */
         function register_shutdown_function($cb)
         {
             if (!Daemon::$context instanceof \PHPDaemon\Request\Generic) {
                 return false;
             }
             return Daemon::$context->registerShutdownFunction($cb);
         }
         $this->override('register_shutdown_function');
         runkit_function_copy('create_function', 'create_function_native');
         runkit_function_redefine('create_function', '$arg,$body', 'return \\PHPDaemon\\Core\\Daemon::$process->createFunction($arg,$body);');
     }
 }
开发者ID:cobolbaby,项目名称:phpdaemon,代码行数:79,代码来源:Worker.php

示例12: testMysqliDBI

 /**
  * Test for mysqli related functions, using runkit_function_redefine
  *
  * @return void
  *
  * @group medium
  */
 public function testMysqliDBI()
 {
     if (!PMA_HAS_RUNKIT) {
         $this->markTestSkipped("Cannot redefine function");
     }
     //FOR UT, we just test the right mysql client API is called
     runkit_function_redefine('mysqli_real_connect', '', 'return "mysqli_real_connect";');
     runkit_function_redefine('mysqli_init', '', 'return "mysqli_init";');
     runkit_function_redefine('mysqli_options', '', 'return "mysqli_options";');
     runkit_function_redefine('mysqli_query', '', 'return "mysqli_query";');
     runkit_function_redefine('mysqli_multi_query', '', 'return "mysqli_multi_query";');
     runkit_function_redefine('mysqli_fetch_array', '', 'return "mysqli_fetch_array";');
     runkit_function_redefine('mysqli_data_seek', '', 'return "mysqli_data_seek";');
     runkit_function_redefine('mysqli_more_results', '', 'return "mysqli_more_results";');
     runkit_function_redefine('mysqli_next_result', '', 'return "mysqli_next_result";');
     runkit_function_redefine('mysqli_get_host_info', '', 'return "mysqli_get_host_info";');
     runkit_function_redefine('mysqli_get_proto_info', '', 'return "mysqli_get_proto_info";');
     runkit_function_redefine('mysqli_get_client_info', '', 'return "mysqli_get_client_info";');
     $user = 'PMA_user';
     $password = 'PMA_password';
     $is_controluser = false;
     $server = array('port' => 8080, 'socket' => 123, 'host' => 'locahost');
     $auxiliary_connection = true;
     //test for connect
     $ret = $this->object->connect($user, $password, $is_controluser, $server, $auxiliary_connection);
     $this->assertEquals('mysqli_init', $ret);
     //test for realQuery
     $query = 'select * from DBI';
     $link = $ret;
     $options = 0;
     $ret = $this->object->realQuery($query, $link, $options);
     $this->assertEquals('mysqli_query', $ret);
     //test for realMultiQuery
     $ret = $this->object->realMultiQuery($link, $query);
     $this->assertEquals('mysqli_multi_query', $ret);
     //test for fetchArray
     $result = $ret;
     $ret = $this->object->fetchArray($result);
     $this->assertEquals('mysqli_fetch_array', $ret);
     //test for fetchAssoc
     $result = $ret;
     $ret = $this->object->fetchAssoc($result);
     $this->assertEquals('mysqli_fetch_array', $ret);
     //test for fetchRow
     $result = $ret;
     $ret = $this->object->fetchRow($result);
     $this->assertEquals('mysqli_fetch_array', $ret);
     //test for dataSeek
     $result = $ret;
     $offset = 10;
     $ret = $this->object->dataSeek($result, $offset);
     $this->assertEquals('mysqli_data_seek', $ret);
     //test for moreResults
     $link = $ret;
     $ret = $this->object->moreResults($link);
     $this->assertEquals('mysqli_more_results', $ret);
     //test for nextResult
     $link = $ret;
     $ret = $this->object->nextResult($link);
     $this->assertEquals('mysqli_next_result', $ret);
     //test for getHostInfo
     $link = $ret;
     $ret = $this->object->getHostInfo($link);
     $this->assertEquals('mysqli_get_host_info', $ret);
     //test for getProtoInfo
     $link = $ret;
     $ret = $this->object->getProtoInfo($link);
     $this->assertEquals('mysqli_get_proto_info', $ret);
     //test for getClientInfo
     $ret = $this->object->getClientInfo();
     $this->assertEquals('mysqli_get_client_info', $ret);
 }
开发者ID:pboutin44,项目名称:maintest,代码行数:79,代码来源:DBIMysqliTest.php

示例13: testParseReturnsAstOnSuccess

 /**
  * Test that parse() returns an ast array on success.
  *
  * @requires extension runkit
  * @covers   Lunr\Shadow\GetoptCliParser::parse
  */
 public function testParseReturnsAstOnSuccess()
 {
     runkit_function_redefine('getopt', '', self::PARSE_WORKS);
     $value = $this->class->parse();
     $this->assertInternalType('array', $value);
     $this->assertEquals(array('a' => array(), 'b' => array('arg')), $value);
 }
开发者ID:rubendgr,项目名称:lunr,代码行数:13,代码来源:GetoptCliParserParseTest.php

示例14: createFunction

 /**
  * Creates runkit function to be used for mocking, taking care of callback to this object.
  *
  * Also temporary renames the original function if there is.
  */
 protected function createFunction()
 {
     if (function_exists($this->function_name)) {
         $this->restore_name = 'restore_' . $this->function_name . '_' . $this->id . '_' . uniqid();
         runkit_function_copy($this->function_name, $this->restore_name);
         runkit_function_redefine($this->function_name, '', $this->getCallback());
     } else {
         runkit_function_add($this->function_name, '', $this->getCallback());
     }
     $this->active = true;
 }
开发者ID:tcz,项目名称:phpunit-mockfunction,代码行数:16,代码来源:MockFunction.php

示例15: overrideNativeFuncs

 /**
  * Overrides native PHP functions.
  * @return void
  */
 public function overrideNativeFuncs()
 {
     if (Daemon::supported(Daemon::SUPPORT_RUNKIT_INTERNAL_MODIFY)) {
         runkit_function_rename('header', 'header_native');
         function header()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return call_user_func_array(array(Daemon::$req, 'header'), func_get_args());
             }
         }
         runkit_function_rename('is_uploaded_file', 'is_uploaded_file_native');
         function is_uploaded_file()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return call_user_func_array(array(Daemon::$req, 'isUploadedFile'), func_get_args());
             }
         }
         runkit_function_rename('move_uploaded_file', 'move_uploaded_file_native');
         function move_uploaded_file()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return call_user_func_array(array(Daemon::$req, 'moveUploadedFile'), func_get_args());
             }
         }
         runkit_function_rename('headers_sent', 'headers_sent_native');
         function headers_sent()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return Daemon::$req->headers_sent();
             }
         }
         runkit_function_rename('headers_list', 'headers_list_native');
         function headers_list()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return Daemon::$req->headers_list();
             }
         }
         runkit_function_rename('setcookie', 'setcookie_native');
         function setcookie()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return call_user_func_array(array(Daemon::$req, 'setcookie'), func_get_args());
             }
         }
         register_shutdown_function(array($this, 'shutdown'));
         runkit_function_rename('register_shutdown_function', 'register_shutdown_function_native');
         function register_shutdown_function($cb)
         {
             if (Daemon::$req) {
                 return Daemon::$req->registerShutdownFunction($cb);
             }
         }
         runkit_function_copy('create_function', 'create_function_native');
         runkit_function_redefine('create_function', '$arg,$body', 'return __create_function($arg,$body);');
         function __create_function($arg, $body)
         {
             static $cache = array();
             static $maxCacheSize = 64;
             static $sorter;
             if ($sorter === NULL) {
                 $sorter = function ($a, $b) {
                     if ($a->hits == $b->hits) {
                         return 0;
                     }
                     return $a->hits < $b->hits ? 1 : -1;
                 };
             }
             $crc = crc32($arg . "" . $body);
             if (isset($cache[$crc])) {
                 ++$cache[$crc][1];
                 return $cache[$crc][0];
             }
             if (sizeof($cache) >= $maxCacheSize) {
                 uasort($cache, $sorter);
                 array_pop($cache);
             }
             $cache[$crc] = array($cb = eval('return function(' . $arg . '){' . $body . '};'), 0);
             return $cb;
         }
     }
 }
开发者ID:J3FF3,项目名称:phpdaemon,代码行数:86,代码来源:Daemon_WorkerThread.php


注:本文中的runkit_function_redefine函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。