/
Factory.php
91 lines (81 loc) · 2.07 KB
/
Factory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Query Auth: Signature generation and validation for REST API query authentication
*
* @copyright 2013-2014 Jeremy Kendall
* @license https://github.com/jeremykendall/query-auth/blob/master/LICENSE MIT
* @link https://github.com/jeremykendall/query-auth
*/
namespace QueryAuth;
use QueryAuth\Request\RequestSigner;
use QueryAuth\Request\RequestValidator;
use QueryAuth\Signature;
use RandomLib\Factory as RandomFactory;
/**
* Creates QueryAuth classes
*/
class Factory
{
/**
* @var RandomFactory RandomLib Factory
*/
private $randomFactory;
/**
* Creates a client instance
*
* @return RequestSigner RequestSigner instance
*/
public function newRequestSigner()
{
return new RequestSigner($this->newSignature(), $this->newKeyGenerator());
}
/**
* Creates a RequestValidator
*
* @return RequestValidator RequestValidator instance
*/
public function newRequestValidator()
{
return new RequestValidator($this->newSignature());
}
/**
* Creates new KeyGenerator created with medium strength RandomLib\Generator
*/
public function newKeyGenerator()
{
return new KeyGenerator(
$this->getRandomFactory()->getMediumStrengthGenerator()
);
}
/**
* Creates a Signature instance
*
* @return Signature Signature instance
*/
protected function newSignature()
{
return new Signature();
}
/**
* Get an instance of RandomFactory. If property is null, creates a new
* instance.
*
* @return RandomFactory Instance of RandomFactory
*/
public function getRandomFactory()
{
if ($this->randomFactory === null) {
$this->randomFactory = new RandomFactory();
}
return $this->randomFactory;
}
/**
* Set randomFactory
*
* @param RandomFactory $randomFactory Instance of RandomFactory
*/
public function setRandomFactory(RandomFactory $randomFactory)
{
$this->randomFactory = $randomFactory;
}
}