Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
3 / 6
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
TokenParams
50.00% covered (danger)
50.00%
3 / 6
0.00% covered (danger)
0.00%
0 / 1
4.12
0.00% covered (danger)
0.00%
0 / 1
 __construct
50.00% covered (danger)
50.00%
3 / 6
0.00% covered (danger)
0.00%
0 / 1
4.12
1<?php
2namespace Ably\Models;
3
4/**
5 * Provides parameters of a token request.
6 */
7class TokenParams extends BaseOptions {
8
9    /**
10     * @var integer Requested time to live for the token in milliseconds. If the token request
11     * is successful, the TTL of the returned token will be less than or equal to this value depending
12     * on application settings and the attributes of the issuing key.
13     */
14    public $ttl;
15
16    /**
17     * @var string Capability of the token. If the token request is successful,
18     * the capability of the returned token will be the intersection of
19     * this capability with the capability of the issuing key.
20     */
21    public $capability;
22
23    /**
24     * @var string A clientId to associate with this token. The generated token
25     * may be used to authenticate as this clientId.
26     */
27    public $clientId;
28
29    /**
30     * @var integer The timestamp (in millis since the epoch) of this request.
31     * Timestamps, in conjunction with the nonce, are used to prevent
32     * token requests from being replayed.
33     */
34    public $timestamp;
35    
36    /**
37     * Constructor. Automatically canonicalizes capability, if provided as array or object.
38     * If capability is a string, it is assumed that it's already a canonicalized json_encoded string.
39     */
40    public function __construct( $options = [] ) {
41        parent::__construct( $options );
42
43        if (is_object( $this->capability )) {
44            $this->capability = (array) $this->capability;
45        }
46
47        if (is_array( $this->capability )) {
48            ksort( $this->capability );
49            $this->capability = json_encode( $this->capability );
50        }
51    }
52}