-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathConfig.php
More file actions
195 lines (155 loc) · 4.88 KB
/
Config.php
File metadata and controls
195 lines (155 loc) · 4.88 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
namespace Phprest;
use InvalidArgumentException;
use League\BooBoo\BooBoo;
use League\Container\Container;
use League\Container\ContainerInterface;
use League\Event\Emitter as EventEmitter;
use League\Event\EmitterInterface as EventEmitterInterface;
use League\Route\Strategy\StrategyInterface;
use Phprest\ErrorHandler\Formatter\JsonXml as JsonXmlFormatter;
use Phprest\ErrorHandler\Handler\Log as LogHandler;
use Phprest\Router\RouteCollection;
use Phprest\Router\Strategy as RouterStrategy;
use Phprest\Service\Hateoas\Config as HateoasConfig;
use Phprest\Service\Hateoas\Service as HateoasService;
use Phprest\Service\Logger\Config as LoggerConfig;
use Phprest\Service\Logger\Service as LoggerService;
class Config
{
protected string $vendor;
protected string $apiVersion;
protected bool $debug = false;
protected ContainerInterface $container;
protected RouteCollection $router;
protected EventEmitterInterface $eventEmitter;
protected BooBoo $errorHandler;
protected HateoasConfig $hateoasConfig;
protected HateoasService $hateoasService;
protected LoggerConfig $loggerConfig;
protected LoggerService $loggerService;
protected LogHandler $logHandler;
public function __construct(string $vendor, string $apiVersion, bool $debug = false)
{
if (! preg_match('#^' . Application::API_VERSION_REG_EXP . '$#', $apiVersion)) {
throw new InvalidArgumentException('Api version is not valid');
}
$this->vendor = $vendor;
$this->apiVersion = $apiVersion;
$this->debug = $debug;
$this->setContainer(new Container());
$this->setRouter(new RouteCollection($this->getContainer()));
$this->setEventEmitter(new EventEmitter());
$this->setHateoasConfig(new HateoasConfig($debug));
$this->setHateoasService(new HateoasService());
$this->setLoggerConfig(new LoggerConfig('phprest'));
$this->setLoggerService(new LoggerService());
$this->setLogHandler(new LogHandler());
$this->setRouterStrategy(new RouterStrategy($this->getContainer()));
$errorHandler = new BooBoo([new JsonXmlFormatter($this)]);
$errorHandler->silenceAllErrors(false);
$errorHandler->treatErrorsAsExceptions(true);
$this->setErrorHandler($errorHandler);
}
public function getVendor(): string
{
return $this->vendor;
}
public function getApiVersion(): string
{
return $this->apiVersion;
}
public function isDebug(): bool
{
return $this->debug;
}
public function setContainer(ContainerInterface $container): self
{
$this->container = $container;
return $this;
}
/**
* @return ContainerInterface
*/
public function getContainer()
{
return $this->container;
}
public function setRouter(RouteCollection $router): self
{
$this->router = $router;
return $this;
}
public function setRouterStrategy(StrategyInterface $strategy): self
{
$this->router->setStrategy($strategy);
return $this;
}
public function getRouter(): RouteCollection
{
return $this->router;
}
public function setEventEmitter(EventEmitterInterface $eventEmitter): self
{
$this->eventEmitter = $eventEmitter;
return $this;
}
public function getEventEmitter(): EventEmitterInterface
{
return $this->eventEmitter;
}
public function setErrorHandler(BooBoo $errorHandler): self
{
$this->errorHandler = $errorHandler;
return $this;
}
public function getErrorHandler(): BooBoo
{
return $this->errorHandler;
}
public function setHateoasConfig(HateoasConfig $config): self
{
$this->hateoasConfig = $config;
return $this;
}
public function getHateoasConfig(): HateoasConfig
{
return $this->hateoasConfig;
}
public function setHateoasService(HateoasService $service): self
{
$this->hateoasService = $service;
return $this;
}
public function getHateoasService(): HateoasService
{
return $this->hateoasService;
}
public function setLoggerConfig(LoggerConfig $config): self
{
$this->loggerConfig = $config;
return $this;
}
public function getLoggerConfig(): LoggerConfig
{
return $this->loggerConfig;
}
public function setLoggerService(LoggerService $service): self
{
$this->loggerService = $service;
return $this;
}
public function getLoggerService(): LoggerService
{
return $this->loggerService;
}
public function setLogHandler(LogHandler $logHandler): self
{
$this->logHandler = $logHandler;
return $this;
}
public function getLogHandler(): LogHandler
{
return $this->logHandler;
}
}