fkooman\OAuth\Client\TokenResponse::__construct PHP Method

__construct() public method

public __construct ( array $data )
$data array
    public function __construct(array $data)
    {
        foreach (array('access_token', 'token_type') as $key) {
            if (!array_key_exists($key, $data)) {
                throw new TokenResponseException(sprintf("missing field '%s'", $key));
            }
        }
        $this->setAccessToken($data['access_token']);
        $this->setTokenType($data['token_type']);
        $this->expiresIn = null;
        $this->refreshToken = null;
        $this->scope = null;
        if (array_key_exists('expires_in', $data)) {
            $this->setExpiresIn($data['expires_in']);
        }
        if (array_key_exists('refresh_token', $data)) {
            $this->setRefreshToken($data['refresh_token']);
        }
        if (array_key_exists('scope', $data)) {
            $this->setScope($data['scope']);
        }
    }

Usage Example

 public function __construct(array $data)
 {
     parent::__construct($data);
     if (array_key_exists('user_id', $data)) {
         $this->user_id_from_provider = $data['user_id'];
     } else {
         $this->user_id_from_provider = false;
     }
 }