Skip to content

Commit c0b478e

Browse files
committed
Add configuration entry for custom error logger implementations
1 parent 146b2c4 commit c0b478e

File tree

1 file changed

+62
-13
lines changed

1 file changed

+62
-13
lines changed

src/WaterPipe/WaterPipeConfig.php

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333
namespace ElementaryFramework\WaterPipe;
3434

35+
use ElementaryFramework\WaterPipe\Configuration\DefaultErrorLogger;
36+
use ElementaryFramework\WaterPipe\Configuration\IErrorLogger;
37+
use ElementaryFramework\WaterPipe\Configuration\StdErrorLogger;
38+
3539
class WaterPipeConfig
3640
{
3741
/**
@@ -71,18 +75,19 @@ public static function get(): WaterPipeConfig
7175
private $_defaultCharset = "utf-8";
7276

7377
/**
74-
* Defines if WaterPipe uses the stderr output channel
75-
* to print errors and uncaught exceptions.
78+
* Defines the error logger to use in WaterPipe.
7679
*
77-
* @var bool
80+
* @var IErrorLogger
7881
*/
79-
private $_useStderr = true;
82+
private $_errorLogger = null;
8083

8184
/**
8285
* WaterPipeConfig constructor.
8386
*/
8487
private function __construct()
85-
{ }
88+
{
89+
$this->_errorLogger = new DefaultErrorLogger();
90+
}
8691

8792
/**
8893
* Checks if query strings are enabled.
@@ -97,14 +102,20 @@ public function isQueryStringEnabled(): bool
97102
/**
98103
* Set the enabled state of query strings.
99104
*
100-
* @param bool $enable
105+
* @param bool $enable true to enable query strings, false otherwise.
106+
*
107+
* @return self
101108
*/
102-
public function setQueryStringEnabled(bool $enable): void
109+
public function setQueryStringEnabled(bool $enable): WaterPipeConfig
103110
{
104111
$this->_queryStringEnabled = $enable;
112+
113+
return $this;
105114
}
106115

107116
/**
117+
* Returns the defined default charset.
118+
*
108119
* @return string
109120
*/
110121
public function getDefaultCharset(): string
@@ -113,33 +124,71 @@ public function getDefaultCharset(): string
113124
}
114125

115126
/**
127+
* Sets the default charset to use when sending responses.
128+
*
116129
* @param string $defaultCharset
130+
*
131+
* @return self
117132
*/
118-
public function setDefaultCharset(string $defaultCharset): void
133+
public function setDefaultCharset(string $defaultCharset): WaterPipeConfig
119134
{
120135
$this->_defaultCharset = $defaultCharset;
136+
137+
return $this;
121138
}
122139

123140
/**
124141
* Checks if WaterPipe print errors and uncaught exceptions in the stderr.
142+
* This method is deprecated and it is not recommended to use it in new projects.
125143
*
144+
* @deprecated 1.3.0
145+
*
126146
* @return bool
127147
*/
128-
public function useStderr()
148+
public function useStderr(): bool
129149
{
130-
return $this->_useStderr;
150+
return $this->_errorLogger instanceof StdErrorLogger;
131151
}
132152

133153
/**
134154
* Set if WaterPipe have to print errors and uncaught exceptions in the stderr.
155+
* This method is deprecated and it is not recommended to use it in new projects.
135156
*
157+
* @deprecated 1.3.0
158+
*
136159
* @param bool $useStderr True to enable, false to disable.
137160
*
138-
* @return self
161+
* @return self
162+
*/
163+
public function setUseStderr(bool $useStderr): WaterPipeConfig
164+
{
165+
$this->_errorLogger = $useStderr
166+
? new StdErrorLogger()
167+
: new DefaultErrorLogger();
168+
169+
return $this;
170+
}
171+
172+
/**
173+
* Gets the error logger currently used by WaterPipe.
174+
*
175+
* @return IErrorLogger
176+
*/
177+
public function errorLogger(): IErrorLogger
178+
{
179+
return $this->_errorLogger;
180+
}
181+
182+
/**
183+
* Defines the error logger to use in WaterPipe.
184+
*
185+
* @param IErrorLogger $errorLogger The error logger.
186+
*
187+
* @return self
139188
*/
140-
public function setUseStderr(bool $useStderr)
189+
public function setErrorLogger(IErrorLogger $errorLogger): WaterPipeConfig
141190
{
142-
$this->_useStderr = $useStderr;
191+
$this->_errorLogger = $errorLogger;
143192

144193
return $this;
145194
}

0 commit comments

Comments
 (0)