1: <?php
2:
3: namespace PHPixie\Auth;
4:
5: class Builder
6: {
7: protected $configData;
8: protected $repositoryRegistry;
9: protected $providerBuilders;
10: protected $contextContainer;
11:
12: protected $instances = array();
13:
14: public function __construct(
15: $configData,
16: $repositoryRegistry = null,
17: $providerBuilders = array(),
18: $contextContainer = null
19: )
20: {
21: $this->configData = $configData;
22: $this->repositoryRegistry = $repositoryRegistry;
23: $this->providerBuilders = $providerBuilders;
24: $this->contextContainer = $contextContainer;
25: }
26:
27: public function domains()
28: {
29: return $this->instance('domains');
30: }
31:
32: public function providers()
33: {
34: return $this->instance('providers');
35: }
36:
37: public function repositories()
38: {
39: return $this->instance('repositories');
40: }
41:
42: public function contextContainer()
43: {
44: if($this->contextContainer === null) {
45: $this->contextContainer = $this->buildContextContainer();
46: }
47:
48: return $this->contextContainer;
49: }
50:
51: public function context()
52: {
53: return $this->contextContainer()->authContext();
54: }
55:
56: public function buildContext()
57: {
58: return new Context();
59: }
60:
61: public function buildContextContainer($context = null)
62: {
63: return new Context\Container\Implementation($context);
64: }
65:
66: public function buildDomain($name, $configData)
67: {
68: return new Domains\Domain($this, $name, $configData);
69: }
70:
71: protected function instance($name)
72: {
73: if(!array_key_exists($name, $this->instances)) {
74: $method = 'build'.ucfirst($name);
75: $this->instances[$name] = $this->$method();
76: }
77:
78: return $this->instances[$name];
79: }
80:
81: protected function buildDomains()
82: {
83: return new Domains(
84: $this,
85: $this->configData->slice('domains')
86: );
87: }
88:
89: protected function buildProviders()
90: {
91: return new Providers(
92: $this->providerBuilders
93: );
94: }
95:
96: protected function buildRepositories()
97: {
98: return new Repositories(
99: $this->repositoryRegistry
100: );
101: }
102: }