Skip to content

Commit a507c34

Browse files
Fix/general fixes (#22)
* [f#21] write server info to STDOUT - Using `echo` would cause issues within the terminal in dev mode. closes #21 * [ch] correct with interface to typehint on in eg's * [f] correct how cookies are being added to the req
1 parent 2b63667 commit a507c34

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

example/app-dev-mode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$slim = new \Slim\App();
66

77
// Some slim configuration
8-
$slim->get('/', function( \Psr\Http\Message\RequestInterface $req, \Psr\Http\Message\ResponseInterface $res) {
8+
$slim->get('/', function( \Psr\Http\Message\ServerRequestInterface $req, \Psr\Http\Message\ResponseInterface $res) {
99

1010
$html = <<<HTML
1111
<html>

example/app-prod-mode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$slim = new \Slim\App();
66

77
// Some slim configuration
8-
$slim->get('/', function( \Psr\Http\Message\RequestInterface $req, \Psr\Http\Message\ResponseInterface $res) {
8+
$slim->get('/', function( \Psr\Http\Message\ServerRequestInterface $req, \Psr\Http\Message\ResponseInterface $res) {
99

1010
$html = <<<HTML
1111
<html>

src/Server.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
Socket\Server as SocketServer,
1111
Http\Server as HttpServer
1212
};
13-
use Slim\ {
13+
use Slim\{
1414
App as SlimInstance,
15+
Http\Cookies as SlimCookies,
1516
Http\Response as SlimResponse
1617
};
1718
use Zend\Diactoros\ {
@@ -140,7 +141,7 @@ public function run()
140141
$request->getMethod(),
141142
$stream,
142143
$request->getHeaders(),
143-
$request->getHeader('cookie'),
144+
SlimCookies::parseHeader($request->getHeader('Cookie')[0]),
144145
$request->getQueryParams()
145146
);
146147

@@ -153,13 +154,15 @@ public function run()
153154
});
154155

155156
if ($this->environment !== ServerEnvironment::PRODUCTION) {
156-
echo sprintf(
157-
" >> Listening on http://%s:%d\n\nAssets allowed to be served: %s\n\nIn %s environment\n\n",
157+
$output = sprintf(
158+
" >> Listening on http://%s:%d\n\nIn %s environment\n\n",
158159
$this->host,
159160
$this->port,
160-
str_replace('|', ', ', $this->whiteListedAssetFileTypes),
161161
ServerEnvironment::getEnvironmentName($this->environment)
162162
);
163+
$terminal = fopen('php://stdout', 'w');
164+
fwrite($terminal, $output);
165+
fclose($terminal);
163166
}
164167

165168
$this->loop->run();

0 commit comments

Comments
 (0)