close() public method

Starts the close sequence
public close ( )
コード例 #1
0
 public function testReplaceOrphanedSession()
 {
     $this->_testResult = null;
     $this->_error = null;
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $this->_conn->getClient()->getCallee()->register($session, 'com.example.orphan_testing', array($this, 'callOrphanTest'), ['replace_orphaned_session' => 'no'])->then(function ($res = null) use($session) {
             $this->_error = 'OrphaningClient not registered';
             $this->_conn->close();
         }, function ($msg = null) use($session) {
             if ($msg instanceof \Thruway\Message\ErrorMessage) {
                 if ($msg->getErrorURI() != 'wamp.error.procedure_already_exists') {
                     $this->_testResult = $msg->getErrorURI();
                     $this->_conn->close();
                 } else {
                     $this->_conn->getClient()->getCallee()->register($session, 'com.example.orphan_testing', array($this, 'callOrphanTest'), ['replace_orphaned_session' => 'yes'])->then(function () use($session) {
                         $session->call('com.example.orphan_testing', [])->then(function ($res) {
                             $this->_conn->close();
                             $this->_testResult = "resolve";
                         }, function ($error = null) {
                             if ($error instanceof \Thruway\Message\ErrorMessage) {
                                 $this->_testResult = $error->getErrorURI();
                             } else {
                                 $this->_testResult = "rejected";
                             }
                             $this->_conn->close();
                         });
                     });
                 }
             }
         });
     });
     $this->_conn->open();
     $this->assertNull($this->_error, "Error was {$this->_error}");
     $this->assertEquals("resolve", $this->_testResult);
 }
コード例 #2
0
 public function testCall()
 {
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $add2 = function ($args, $kwargs, $details) {
             $this->_testCallerId = $details["caller"];
             $this->_testAuthId = $details["authid"];
             $this->_testAuthMethod = $details["authmethod"];
             //                    $this->_testAuthRole = $details["authrole"];
             return $args[0] + $args[1];
         };
         $session->register('com.example.disclosecallertest', $add2, ['disclose_caller' => true])->then(function () use($session) {
             $session->call('com.example.disclosecallertest', [1, 2])->then(function ($res) {
                 $this->_conn->close();
                 $this->_testResult = $res;
             }, function ($error) {
                 $this->_conn->close();
                 $this->_error = $error;
             });
         });
     });
     $this->_conn->getClient()->setAuthId("*****@*****.**");
     $this->_conn->open();
     $this->assertNull($this->_error, "Got this error when making an RPC call: {$this->_error}");
     $this->assertEquals(3, $this->_testResult[0]);
     $this->assertNotEmpty($this->_testCallerId);
     $this->assertEquals("*****@*****.**", $this->_testAuthId);
     $this->assertEquals("simplysimple", $this->_testAuthMethod);
 }
コード例 #3
0
 public function testProcAlreadyExists()
 {
     $this->_error = null;
     $this->_result = null;
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $session->register('test_registration', [$this, "theCallback"])->then(function () use($session) {
             // try registering again to make sure we get an error
             $session->register('test_registration', [$this, "theCallback"])->then(function () use($session) {
                 $this->_error = "Second registration should not have worked";
                 $session->close();
             }, function ($err) use($session) {
                 // should get an error
                 // unregister
                 $session->unregister('test_registration')->then(function () use($session) {
                     $this->_result = "success";
                     $session->close();
                 }, function () {
                     $this->error = "Unregistration failed";
                 });
             });
         }, function ($err) {
             $this->error = "Registration failed";
             $this->_conn->close();
         });
     });
     $this->_conn->open();
     $this->assertNull($this->_error, "Error occurred: " . $this->_error);
     $this->assertEquals("success", $this->_result);
 }
コード例 #4
0
 public function testAuthorizedActions()
 {
     $this->flushRules();
     $challenge = function ($session, $method) {
         return "letMeIn";
     };
     $this->_conn = new \Thruway\Connection(array("realm" => 'authful_realm', "url" => 'ws://127.0.0.1:8090', "max_retries" => 0, "authmethods" => ["simplysimple"], "onChallenge" => $challenge));
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $session->call("add_authorization_rule", [["role" => "sales", "action" => "publish", "uri" => "sales.numbers", "allow" => true]])->then(function ($r) {
             $this->_conn->close();
             $this->_testResult = "ok";
         }, function ($msg) {
             $this->_conn->close();
             $this->_testResult = "failed";
             $this->assertInstanceOf('\\Thruway\\Message\\ErrorMessage', $msg);
             $this->assertEquals("wamp.error.not_authorized", $msg->getErrorUri());
         });
     });
     $this->_conn->open();
     $this->assertEquals("failed", $this->_testResult);
     $this->_testResult = "";
     $this->_error = null;
     $this->_conn = new \Thruway\Connection(["realm" => 'authful_realm', "url" => 'ws://127.0.0.1:8090', "max_retries" => 0, "authmethods" => ["simplysimple"], "onChallenge" => function () {
         return "ozTheGreatAndPowerful";
     }]);
     // now set permissions to allow stuff
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $session->call("add_authorization_rule", [["role" => "sales", "action" => "call", "uri" => "add_authorization_rule", "allow" => true]])->then(function ($r) {
             $this->_conn->close();
             $this->_testResult = "ok";
             $this->assertEquals("ADDED", $r);
         }, function ($msg) {
             $this->_conn->close();
             $this->_error = "error adding authorization rule";
         });
     });
     $this->_conn->open();
     $this->assertNull($this->_error, "Error: " . $this->_error);
     $this->assertEquals("ok", $this->_testResult);
     // now try to use the thing
     $this->_conn = new \Thruway\Connection(array("realm" => 'authful_realm', "url" => 'ws://127.0.0.1:8090', "max_retries" => 0, "authmethods" => ["simplysimple"], "onChallenge" => function () {
         return "letMeIn";
     }));
     $this->_testResult = null;
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $session->call("add_authorization_rule", [["role" => "sales", "action" => "publish", "uri" => "sales.numbers", "allow" => true]])->then(function ($r) {
             $this->_conn->close();
             $this->_testResult = "success";
         }, function ($msg) {
             $this->_conn->close();
             $this->_testResult = "failed";
         });
     });
     $this->_conn->open();
     $this->assertEquals("success", $this->_testResult);
     $this->flushRules();
 }
コード例 #5
0
ファイル: CrossbarTest.php プロジェクト: binaek89/Thruway
 public function testRegister()
 {
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $session->register('com.example.mul2', function ($args) {
             $this->_conn->close();
             $this->_testArgs = $args;
         });
     });
     $this->_conn->open();
     $this->assertGreaterThan(0, $this->_testArgs[0]);
 }
コード例 #6
0
ファイル: EndToEndTest.php プロジェクト: duanejeffers/Thruway
 /**
  * @depends testCall
  */
 public function testUnregister()
 {
     $this->_error = null;
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $callback = function () {
             return "Hello";
         };
         $session->register('com.example.somethingToUnregister', $callback)->then(function () use($session) {
             $session->unregister('com.example.somethingToUnregister')->then(function () {
                 $this->_conn->close();
                 $this->_testResult = "unregistered";
             }, function () {
                 $this->_conn->close();
                 $this->_error = "Error during unregistration";
             });
         }, function () {
             $this->_conn->close();
             $this->_error = "Couldn't even register the call";
         });
         // TODO: test unregistering again
         // TODO: test unregistering a different session's registration
     });
     $this->_conn->open();
     $this->assertNull($this->_error, "Got this error when making an RPC call: {$this->_error}");
     $this->assertEquals('unregistered', $this->_testResult);
 }
コード例 #7
0
ファイル: PingTest.php プロジェクト: pacho104/redbpim
 public function testServerPing()
 {
     $this->_testResult = null;
     $this->_error = null;
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $session->call('com.example.ping', [])->then(function ($res) {
             $this->_conn->close();
             $this->_testResult = $res;
         }, function ($error = null) {
             if ($error instanceof \Thruway\Message\ErrorMessage) {
                 $this->_error = $error->getErrorURI();
             }
             $this->_conn->close();
         });
     });
     $this->_conn->open();
     $this->assertNull($this->_error, "Error is null");
     $this->assertTrue(is_numeric($this->_testResult[0]), "Server ping returned a success");
 }
コード例 #8
0
ファイル: Timezones.php プロジェクト: filsh/yii2-wamp
 protected function onSuccess(\Thruway\Connection $connection, \Thruway\CallResult $result)
 {
     $connection->close();
     if ($result !== null) {
         $return = [];
         foreach ($result as $item) {
             $return[$item->name] = (array) $item;
         }
         return $return;
     }
 }
コード例 #9
0
 public function testSubscribe()
 {
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         /**
          * Subscribe to event
          */
         $session->subscribe('com.example.publish', function ($args, $kwargs = null, $details, $publicationId = null) {
             $this->_testArgs = $args;
             $this->_testPublisherId = $details->publisher;
             $this->_testTopic = $details->topic;
             $this->_testAuthId = $details->authid;
             $this->_testAuthMethod = $details->authmethod;
             $this->_testAuthRole = $details->authroles;
         }, ['disclose_publisher' => true])->then(function () use($session) {
             /**
              * Tell the server to publish
              */
             $session->call('com.example.publish', ['test publish'])->then(function ($res) {
                 $this->_testResult = $res;
             }, function ($error) {
                 $this->_conn->close();
                 $this->_error = $error;
             })->then(function () use($session) {
                 $session->close();
             });
         }, function () use($session) {
             $session->close();
             throw new Exception("subscribe failed.");
         });
     });
     $this->_conn->open();
     $this->assertNull($this->_error, "Got this error when receiving Event: {$this->_error}");
     $this->assertEquals('ok', $this->_testResult[0]);
     $this->assertNotEmpty($this->_testPublisherId);
     $this->assertEquals("anonymous", $this->_testAuthId);
     $this->assertEquals("internalClient", $this->_testAuthMethod);
     $this->assertEquals('com.example.publish', $this->_testTopic);
 }
コード例 #10
0
ファイル: EndToEndTest.php プロジェクト: pacho104/redbpim
 public function xtestCallWithArguments()
 {
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $session->call('com.example.testcallwitharguments', ['testing123'])->then(function ($res) {
             $this->_conn->close();
             $this->_testResult = $res;
         }, function ($error) {
             $this->_conn->close();
             $this->_error = $error;
         });
     });
     $this->_conn->open();
     $this->assertNull($this->_error, "Got this error when making an RPC call: {$this->_error}");
     $this->assertEquals('testing123', $this->_testResult[0]);
 }
コード例 #11
0
ファイル: EndToEndTest.php プロジェクト: binaek89/Thruway
 public function testPublishNoArguments()
 {
     $this->_testResult = null;
     $this->_error = null;
     $this->_conn->on('open', function (\Thruway\ClientSession $session) {
         $session->subscribe("some.topic", function ($args, $argsKw) {
             $this->_testResult = $args;
             $this->_conn->close();
         })->then(function ($asdf) use($session) {
             $session->publish("some.topic", null, null, ["exclude_me" => false]);
         }, function ($err) {
             $this->_error = "Subscribe failed.";
             $this->_conn->close();
         });
     });
     $this->_conn->open();
     $this->assertTrue(is_array($this->_testResult));
     $this->assertEmpty($this->_testResult);
     $this->assertNull($this->_error, "Error: " . $this->_error);
 }
コード例 #12
0
 /**
  * Make WAMP call
  *
  * @param $uri
  * @param array $args
  * @return null
  */
 private function call($uri, $args = [])
 {
     $result = null;
     $realm = 'process_manager';
     $connection = new Connection(['realm' => $realm, 'url' => $this->config['trusted_url'], "max_retries" => 0]);
     $connection->on('open', function (ClientSession $session) use($uri, $args, $connection, &$result) {
         $session->call($uri, $args)->then(function ($res) use($connection, &$result) {
             $result = $res[0];
             $connection->close();
         }, function ($error) use($connection, &$result) {
             $result = $error;
             $connection->close();
         });
     });
     $connection->open();
     return $result;
 }