3

我想在我的项目中将 Jaxl 实现为类,但是所有 Jaxl 示例都是基于函数的。所有示例都使用闭包来运行回调。类中的方法无法像函数基编程那样访问。如何在类中调用 wait_for_register_form()?我的基类实现是这样的(注意粗体注释):

    <?php

    class XmppsController extends AppController {

    public function test() {

        require_once 'JAXL/jaxl.php';
        global $client;

        $client = new JAXL(array(
            'jid' => 'localhost',
            'log_level' => JAXL_INFO
        ));

        $client->require_xep(array(
            '0077'    // InBand Registration   
        ));

         global $thisObj;


        $thisObj = $this;


        $client->add_cb('on_stream_features', function($stanza)  {
            global $client,$thisObj;
            $client->xeps['0077']->get_form('localhost');

            return "wait_for_register_form";  **//it calls wait_for_register_form() function, but I want call this function in class. how can I solve this problem?**
        });

        $client->start();
        echo "done\n";       

    }

    public function wait_for_register_form($event, $args) {
       // something
    }
}
4

1 回答 1

3

演示在基类之外扩展 FSM 状态的示例register_user.php最初并不是为了适应您尝试实现的特定用例而编写的。我已经在J​​AXLFsm中推送了一个补丁,现在可以让你做同样的事情。如果您对细节感兴趣,这里是提交日志。

现在尝试相同的方法,它应该可以工作。

于 2012-10-05T12:46:22.747 回答