Thruway\Connection::__construct PHP Method

__construct() public method

Constructor
public __construct ( array $options, React\EventLoop\LoopInterface $loop = null )
$options array
$loop React\EventLoop\LoopInterface
    public function __construct(array $options, LoopInterface $loop = null)
    {
        $this->options = $options;
        $this->client = new Client($options['realm'], $loop);
        $url = isset($options['url']) ? $options['url'] : null;
        $pawlTransport = new PawlTransportProvider($url);
        $this->client->addTransportProvider($pawlTransport);
        $this->client->setReconnectOptions($options);
        //Set Authid
        if (isset($options['authid'])) {
            $this->client->setAuthId($options['authid']);
        }
        //Register Handlers
        $this->handleOnChallenge();
        $this->handleOnOpen();
        $this->handleOnClose();
        $this->handleOnError();
    }

Usage Example

Example #1
0
 function __construct()
 {
     $this->options = \Drupal::config('thruway.settings')->get('options');
     $loop = \Drupal::service('thruway.loop');
     parent::__construct($this->options, $loop, new ConsoleLogger());
     $this->pluginManager = \Drupal::service('thruway.plugin.manager');
     $this->serializer = \Drupal::service('serializer');
     $this->annotationReader = new AnnotationReader();
     $this->resources = \Drupal::config('thruway.settings')->get('resources');
     //Register the Thruway annotation
     AnnotationRegistry::registerFile(\Drupal::service('module_handler')->getModuleList()['thruway']->getPath() . "/src/Annotation/Thruway.php");
     $this->on('open', [$this, 'onSessionStart']);
     $this->on('close', function ($reason) {
         $this->getClient()->getLogger()->alert("Connection closing because: {$reason}");
     });
     //        $this->getClient()->setLogger(\Drupal::logger("thruway"));
     $this->getClient()->setLogger(new ConsoleLogger());
 }