Nats\ConnectionOptions::__toString PHP Method

__toString() public method

Get the options JSON string.
public __toString ( ) : string
return string
    public function __toString()
    {
        $a = ["lang" => $this->lang, "version" => $this->version, "verbose" => $this->verbose, "pedantic" => $this->pedantic];
        if (!is_null($this->user)) {
            $a["user"] = $this->user;
        }
        if (!is_null($this->pass)) {
            $a["pass"] = $this->pass;
        }
        return json_encode($a);
    }

Usage Example

 /**
  * Test string representation of ConnectionOptions with credentials.
  *
  * @return void
  */
 public function testStringRepresentationWithCredentials()
 {
     $options = new ConnectionOptions();
     $options->setUser("username");
     $options->setPass("password");
     $this->assertEquals("{\"lang\":\"php\",\"version\":\"0.8.0\",\"verbose\":false,\"pedantic\":false,\"user\":\"username\",\"pass\":\"password\"}", $options->__toString());
 }