Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
15 / 18
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ClientOptions
83.33% covered (warning)
83.33%
15 / 18
0.00% covered (danger)
0.00%
0 / 1
6.17
0.00% covered (danger)
0.00%
0 / 1
 __construct
83.33% covered (warning)
83.33%
15 / 18
0.00% covered (danger)
0.00%
0 / 1
6.17
1<?php
2namespace Ably\Models;
3
4use Ably\Log;
5
6/**
7 * Client library options
8 */
9class ClientOptions extends AuthOptions {
10
11    /**
12     * @var boolean value indicating whether or not a TLS (“SSL”) secure connection should be used.
13     */
14    public $tls = true;
15    
16    /**
17     * integer a number controlling the verbosity of the output from 1 (minimum, errors only) to 4 (most verbose);
18     * @see \Ably\Log
19     */
20    public $logLevel = Log::WARNING;
21
22    /**
23     * @var function|null a function to handle each line of log output. If handler is not specified, STDOUT is used.
24     * Note that the log level and log handler have global scope in the library and will thus not act independently between library instances when multiple library instances are existing concurrently.
25     * @see \Ably\Log
26     */
27    public $logHandler;
28
29    /**
30     * @var bool If true, msgpack is used for communication, otherwise JSON is used
31     * note that msgpack is currently NOT SUPPORTED because of lack of working msgpack libraries for PHP
32     */
33    public $useBinaryProtocol = false;
34
35    /**
36     * @var string alternate server domain
37     * For development environments only.
38     */
39    public $restHost;
40
41    /**
42     * @var integer Allows a non-default Ably non-TLS port to be used.
43     * For development environments only.
44     */
45    public $port;
46
47    /**
48     * @var integer Allows a non-default Ably TLS port to be used.
49     * For development environments only.
50     */
51    public $tlsPort;
52
53    /**
54     * @var string optional prefix to be prepended to $restHost
55     * Example: 'sandbox' -> 'sandbox-rest.ably.io'
56     */
57    public $environment;
58
59    /**
60     * @var string[] fallback hosts, used when connection to default host fails, populated automatically
61     */
62    public $fallbackHosts;
63
64    /**
65     * @var \Ably\Models\TokenParams defaultTokenParams – overrides the client library defaults described in TokenParams
66     */
67    public $defaultTokenParams;
68
69    /**
70     * @var integer Timeout for opening the connection
71     * Warning: may be rounded down on some OSes and values < 1000 will always fail in that case.
72     */
73    public $httpOpenTimeout = 4000;
74
75    /**
76     * @var integer connection timeout after which a next fallback host is used
77     */
78    public $httpRequestTimeout = 10000;
79
80    /**
81     * @var integer Max number of fallback host retries for HTTP requests that fail due to network issues or server problems
82     */
83    public $httpMaxRetryCount = 3;
84
85    /**
86     * @var integer Max elapsed time in which fallback host retries for HTTP requests will be attempted
87     */
88    public $httpMaxRetryDuration = 15000;
89
90    /**
91     * @var string a class that should be used for making HTTP connections
92     * To allow mocking in tests.
93     */
94    public $httpClass = 'Ably\Http';
95
96    /**
97     * @var string a class that should be used for Auth
98     * To allow mocking in tests.
99     */
100    public $authClass = 'Ably\Auth';
101
102    public function __construct( $options = [] ) {
103        parent::__construct( $options );
104
105        if ( empty( $this->restHost ) ) {
106            $this->restHost = 'rest.ably.io';
107
108            if ( empty( $this->environment ) ) {
109                // default fallback hosts are used only with the default host and default environment
110                $this->fallbackHosts = [
111                    'a.ably-realtime.com',
112                    'b.ably-realtime.com',
113                    'c.ably-realtime.com',
114                    'd.ably-realtime.com',
115                    'e.ably-realtime.com',
116                ];
117
118                shuffle( $this->fallbackHosts );
119            }
120        } else { // custom host
121            if ( !empty( $this->fallbackHosts ) ) {
122                shuffle( $this->fallbackHosts );
123            }
124        }
125
126        if ( empty( $this->defaultTokenParams ) ) {
127            $this->defaultTokenParams = new TokenParams();
128        }
129
130        if ( !empty( $this->environment ) ) {
131            $this->restHost = $this->environment . '-' . $this->restHost;
132        }
133    }
134}