Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First stab at the StreamResponse, see #12988 The idea is to use an interface ICallbackResponse (I'm not 100% happy with the name yet, suggestions?) that allow the response to output things in its own way, for instance stream the file using readfile Unittests are atm lacking, plan is to check if a mock of ICallbackResponse will be used by calling its callback (also unhappy with this name) method Usage is: $response = new StreamResponse('path/to/file');
- Loading branch information
1 parent
c6705ab
commit b716c3b
Showing
7 changed files
with
175 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* @author Bernhard Posselt | ||
* @copyright 2015 Bernhard Posselt <dev@bernhard-posselt.com> | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace OC\AppFramework\Http; | ||
|
||
/** | ||
* Very thin wrapper class to make output testable | ||
*/ | ||
class IO { | ||
|
||
/** | ||
* @param $out | ||
*/ | ||
public function setOutput($out) { | ||
print($out); | ||
} | ||
|
||
/** | ||
* @param $header | ||
*/ | ||
public function setHeader($header) { | ||
header($header); | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @param $value | ||
* @param $expire | ||
* @param $path | ||
* @param $domain | ||
* @param $secure | ||
* @param $httponly | ||
*/ | ||
public function setCookie($name, $value, $expire, $path, $domain, $secure, $httponly) { | ||
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* @author Bernhard Posselt | ||
* @copyright 2015 Bernhard Posselt <dev@bernhard-posselt.com> | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace OCP\AppFramework\Http; | ||
|
||
/** | ||
* Interface ICallbackResponse | ||
* | ||
* @package OCP\AppFramework\Http | ||
*/ | ||
interface ICallbackResponse { | ||
|
||
/** | ||
* Outputs the content that should be printed | ||
*/ | ||
function callback(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* @author Bernhard Posselt | ||
* @copyright 2015 Bernhard Posselt <dev@bernhard-posselt.com> | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace OCP\AppFramework\Http; | ||
|
||
/** | ||
* Class StreamResponse | ||
* | ||
* @package OCP\AppFramework\Http | ||
*/ | ||
class StreamResponse extends Response implements ICallbackResponse { | ||
/** @var string */ | ||
private $filePath; | ||
|
||
/** | ||
* @param string $filePath the path to the file which should be streamed | ||
*/ | ||
public function __construct ($filePath) { | ||
$this->filePath = $filePath; | ||
} | ||
|
||
|
||
/** | ||
* Streams the file using readfile | ||
*/ | ||
public function callback () { | ||
@readfile($this->filePath); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters