コード例 #1
0
ファイル: TokenBuilder.php プロジェクト: devhelp/token
 /**
  * @param TokenDefinition $definition
  * @return Token
  */
 public function build(TokenDefinition $definition)
 {
     $token = $this->getToken($definition->getClass());
     $token->setType($definition->getType());
     $token->setHash($this->generateHash($definition->getHashAlgorithm()));
     $token->setUsages($definition->getUsages());
     $token->setExpiresAt($this->calculateExpirationDate($definition->getTtl()));
     return $token;
 }
コード例 #2
0
ファイル: TokenBuilderSpec.php プロジェクト: devhelp/token
 function it_builds_token_according_to_given_TokenDefinition(TokenDefinition $definition)
 {
     $baseDate = new \DateTime('2000-01-01');
     $type = 'test';
     $expiresAt = new \DateTime('2000-01-04');
     $usages = 0;
     $definition->getClass()->willReturn('Devhelp\\Token\\Token');
     $definition->getType()->willReturn($type);
     $definition->getTtl()->willReturn('3 days');
     $definition->getUsages()->willReturn($usages);
     $definition->getHashAlgorithm()->willReturn('test_alg');
     $this->setBaseDate($baseDate)->build($definition)->shouldReturnTokenWith($type, $expiresAt, $usages, $this->hash);
 }
コード例 #3
0
ファイル: TokenDefinitionSpec.php プロジェクト: devhelp/token
 function it_does_not_merge_token_definition_if_values_were_already_set(TokenDefinition $definition)
 {
     $class = 'My\\Class';
     $hashAlgorithm = 'my_alg';
     $usages = 3;
     $ttl = '3 days';
     $this->setClass($class);
     $this->setHashAlgorithm($hashAlgorithm);
     $this->setUsages($usages);
     $this->setTtl($ttl);
     $definition->getClass()->willReturn('My\\Class2');
     $definition->getHashAlgorithm()->willReturn('test_alg');
     $definition->getUsages()->willReturn(0);
     $definition->getTtl()->willReturn('1 day');
     $token = $this->merge($definition);
     $token->getClass()->shouldReturn($class);
     $token->getHashAlgorithm()->shouldReturn($hashAlgorithm);
     $token->getUsages()->shouldReturn($usages);
     $token->getTtl()->shouldReturn($ttl);
 }