Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tal
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Flori
tal
Commits
58211d35
Verified
Commit
58211d35
authored
6 years ago
by
Thomas Flori
Browse files
Options
Downloads
Patches
Plain Diff
use a wrapper class to be able to test send functionality
parent
a40b9681
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Server.php
+40
-0
40 additions, 0 deletions
src/Server.php
src/ServerResponse.php
+8
-5
8 additions, 5 deletions
src/ServerResponse.php
with
48 additions
and
5 deletions
src/Server.php
0 → 100644
+
40
−
0
View file @
58211d35
<?php
namespace
Tal
;
/**
* Class Server
*
* This class is a stupid wrapper for php functions for testing.
*
* @package Tal
* @author Thomas Flori <thflori@gmail.com>
* @codeCoverageIgnore trivial
*/
class
Server
{
/**
* Send a raw HTTP header
*
* @link http://php.net/manual/en/function.header.php
* @param string $string The header string
* @param bool $replace
* @param int $responseCode
* @return void
*/
public
function
header
(
$string
,
$replace
=
true
,
$responseCode
=
null
)
{
header
(
$string
,
$replace
,
$responseCode
);
}
/**
* Echos the given $string
*
* @param $string
* @return void
*/
public
function
echo
(
$string
)
{
echo
(
$string
);
}
}
This diff is collapsed.
Click to expand it.
src/ServerResponse.php
+
8
−
5
View file @
58211d35
...
...
@@ -17,16 +17,19 @@ class ServerResponse extends Response implements ServerResponseInterface
/**
* Sends this response to the client.
*
* @param int $bufferSize
* @param Server|null $server
* @return static
*/
public
function
send
(
int
$bufferSize
=
8192
)
public
function
send
(
int
$bufferSize
=
8192
,
Server
$server
=
null
)
{
$server
=
$server
??
new
Server
();
foreach
(
$this
->
getHeaders
()
as
$name
=>
$values
)
{
if
(
strtolower
(
$name
)
!==
'set-cookie'
)
{
header
(
sprintf
(
'%s: %s'
,
$name
,
implode
(
','
,
$values
)),
false
);
$server
->
header
(
sprintf
(
'%s: %s'
,
$name
,
implode
(
','
,
$values
)),
false
);
}
else
{
foreach
(
$values
as
$value
)
{
header
(
sprintf
(
'%s: %s'
,
$name
,
$value
),
false
);
$server
->
header
(
sprintf
(
'%s: %s'
,
$name
,
$value
),
false
);
}
}
}
...
...
@@ -37,14 +40,14 @@ class ServerResponse extends Response implements ServerResponseInterface
$this
->
getStatusCode
(),
$this
->
getReasonPhrase
()
);
header
(
$http_line
,
true
,
$this
->
getStatusCode
());
$server
->
header
(
$http_line
,
true
,
$this
->
getStatusCode
());
$stream
=
$this
->
getBody
();
if
(
$stream
->
isSeekable
())
{
$stream
->
rewind
();
}
while
(
!
$stream
->
eof
())
{
echo
$stream
->
read
(
$bufferSize
);
$server
->
echo
(
$stream
->
read
(
$bufferSize
)
)
;
}
return
$this
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment