1: <?php
2:
3: namespace PHPixie\Security;
4:
5: class Builder
6: {
7: protected $database;
8:
9: protected $instances = array();
10:
11: public function __construct($database)
12: {
13: $this->database = $database;
14: }
15:
16: public function password()
17: {
18: return $this->instance('password');
19: }
20:
21: public function random()
22: {
23: return $this->instance('random');
24: }
25:
26: public function tokens()
27: {
28: return $this->instance('tokens');
29: }
30:
31: protected function instance($name)
32: {
33: if(!array_key_exists($name, $this->instances)) {
34: $method = 'build'.ucfirst($name);
35: $this->instances[$name] = $this->$method();
36: }
37:
38: return $this->instances[$name];
39: }
40:
41: protected function buildPassword()
42: {
43: return new Password();
44: }
45:
46: protected function buildRandom()
47: {
48: return new Random();
49: }
50:
51: protected function buildTokens()
52: {
53: return new Tokens(
54: $this,
55: $this->database
56: );
57: }
58: }