serialize() public méthode

public serialize ( Token $token ) : string
$token Emarref\Jwt\Token
Résultat string
Exemple #1
0
 public function testSerialize()
 {
     // Configure payload
     $headerParameters = $this->getMockBuilder('Emarref\\Jwt\\Token\\PropertyList')->getMock();
     $headerParameters->expects($this->once())->method('jsonSerialize')->will($this->returnValue('{"a":"1"}'));
     $header = $this->getMockBuilder('Emarref\\Jwt\\Token\\Header')->getMock();
     $header->expects($this->once())->method('getParameters')->will($this->returnValue($headerParameters));
     // Configure payload
     $claims = $this->getMockBuilder('Emarref\\Jwt\\Token\\PropertyList')->getMock();
     $claims->expects($this->once())->method('jsonSerialize')->will($this->returnValue('{"b":"2"}'));
     $payload = $this->getMockBuilder('Emarref\\Jwt\\Token\\Payload')->getMock();
     $payload->expects($this->once())->method('getClaims')->will($this->returnValue($claims));
     // Configure token
     $token = $this->getMockBuilder('Emarref\\Jwt\\Token')->getMock();
     $token->expects($this->once())->method('getHeader')->will($this->returnValue($header));
     $token->expects($this->once())->method('getPayload')->will($this->returnValue($payload));
     $token->expects($this->once())->method('getSignature')->will($this->returnValue('c'));
     // Configure encoding
     $this->encoding->expects($this->exactly(3))->method('encode')->will($this->returnValueMap([['{"a":"1"}', 'a'], ['{"b":"2"}', 'b'], ['c', 'c']]));
     $jwt = $this->serializer->serialize($token);
     $this->assertSame('a.b.c', $jwt);
 }
Exemple #2
0
 /**
  * @param Token                          $token
  * @param Encryption\EncryptionInterface $encryption
  * @return string
  */
 public function serialize(Token $token, Encryption\EncryptionInterface $encryption)
 {
     $this->sign($token, $encryption);
     $serialization = new Serialization\Compact($this->encoder, new HeaderParameter\Factory(), new Claim\Factory());
     return $serialization->serialize($token);
 }