guid() public static méthode

Returns a GUID for use in REST calls.
See also: http://en.wikipedia.org/wiki/Globally_unique_identifier
public static guid ( ) : string
Résultat string
Exemple #1
0
 public function testGuid()
 {
     $guid = Util::guid();
     // ensure proper length
     $this->assertEquals(36, strlen($guid));
     // Make sure in proper format
     $guid = explode('-', $guid);
     $this->assertEquals(8, strlen($guid[0]));
     $this->assertEquals(4, strlen($guid[1]));
     $this->assertEquals(4, strlen($guid[2]));
     $this->assertEquals(4, strlen($guid[3]));
     $this->assertEquals(12, strlen($guid[4]));
 }
 /**
  * @inheritdoc
  */
 public function createToken(array $payload = array())
 {
     if (isset($payload['pairingCode']) && 1 !== preg_match('/^[a-zA-Z0-9]{7}$/', $payload['pairingCode'])) {
         throw new \Exception('[ERROR] In Client::createToken(): The pairing code provided is not legal.');
     }
     $this->request = $this->createNewRequest();
     $this->request->setMethod(Request::METHOD_POST);
     $this->request->setPath('tokens');
     $payload['guid'] = Util::guid();
     $this->request->setBody(json_encode($payload));
     $this->response = $this->sendRequest($this->request);
     $body = json_decode($this->response->getBody(), true);
     if (isset($body['error'])) {
         throw new \Bitpay\Client\BitpayException($this->response->getStatusCode() . ': ' . $body['error']);
     }
     $tkn = $body['data'][0];
     $createdAt = new \DateTime();
     $pairingExpiration = new \DateTime();
     $token = new \Bitpay\Token();
     $token->setPolicies($tkn['policies'])->setToken($tkn['token'])->setFacade($tkn['facade'])->setCreatedAt($createdAt->setTimestamp(floor($tkn['dateCreated'] / 1000)));
     if (isset($tkn['resource'])) {
         $token->setResource($tkn['resource']);
     }
     if (isset($tkn['pairingCode'])) {
         $token->setPairingCode($tkn['pairingCode']);
         $token->setPairingExpiration($pairingExpiration->setTimestamp(floor($tkn['pairingExpiration'] / 1000)));
     }
     return $token;
 }