-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
625 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Contributte\Application\Response\Fly\Adapter; | ||
|
||
use Nette\Http\IRequest; | ||
use Nette\Http\IResponse; | ||
|
||
interface Adapter | ||
{ | ||
|
||
/** | ||
* @param IRequest $request | ||
* @param IResponse $response | ||
* @return void | ||
*/ | ||
public function send(IRequest $request, IResponse $response); | ||
|
||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Contributte\Application\Response\Fly\Adapter; | ||
|
||
use Nette\Http\IRequest; | ||
use Nette\Http\IResponse; | ||
|
||
class CallbackAdapter implements Adapter | ||
{ | ||
|
||
/** @var callable */ | ||
private $callback; | ||
|
||
/** | ||
* @param callable $callback | ||
*/ | ||
public function __construct(callable $callback) | ||
{ | ||
$this->callback = $callback; | ||
} | ||
|
||
/** | ||
* @param IRequest $request | ||
* @param IResponse $response | ||
* @return void | ||
*/ | ||
public function send(IRequest $request, IResponse $response) | ||
{ | ||
call_user_func_array($this->callback, [$request, $response]); | ||
} | ||
|
||
} |
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,55 @@ | ||
<?php | ||
|
||
namespace Contributte\Application\Response\Fly\Adapter; | ||
|
||
use Contributte\Application\Response\Fly\Buffer\ProcessBuffer; | ||
use Nette\Http\IRequest; | ||
use Nette\Http\IResponse; | ||
|
||
class ProcessAdapter implements Adapter | ||
{ | ||
|
||
/** @var string */ | ||
private $command; | ||
|
||
/** @var string */ | ||
private $mode; | ||
|
||
/** @var int */ | ||
private $buffersize; | ||
|
||
/** | ||
* @param string $command | ||
* @param string $mode | ||
* @param int $buffersize | ||
*/ | ||
public function __construct($command, $mode = 'r', $buffersize = 8192) | ||
{ | ||
$this->command = $command; | ||
$this->mode = $mode; | ||
$this->buffersize = $buffersize; | ||
} | ||
|
||
/** | ||
* @param IRequest $request | ||
* @param IResponse $response | ||
* @return void | ||
*/ | ||
public function send(IRequest $request, IResponse $response) | ||
{ | ||
// Open file Buffer | ||
$b = new ProcessBuffer($this->command, $this->mode); | ||
|
||
while (!$b->eof()) { | ||
// Read from Buffer | ||
$output = $b->read($this->buffersize); | ||
|
||
// Goes to ouput | ||
echo $output; | ||
} | ||
|
||
// Close file Buffer | ||
$b->close(); | ||
} | ||
|
||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Contributte\Application\Response\Fly\Adapter; | ||
|
||
use Contributte\Application\Response\Fly\Buffer\FileBuffer; | ||
use Nette\Http\IRequest; | ||
use Nette\Http\IResponse; | ||
|
||
class StdoutAdapter implements Adapter | ||
{ | ||
|
||
/** @var callable */ | ||
private $callback; | ||
|
||
/** | ||
* @param callable $callback | ||
*/ | ||
public function __construct(callable $callback) | ||
{ | ||
$this->callback = $callback; | ||
} | ||
|
||
/** | ||
* @param IRequest $request | ||
* @param IResponse $response | ||
* @return void | ||
*/ | ||
public function send(IRequest $request, IResponse $response) | ||
{ | ||
// Open file pointer | ||
$b = new FileBuffer('php://output', 'w'); | ||
|
||
// Fire callback with Buffer, request and response | ||
call_user_func_array($this->callback, [$b, $request, $response]); | ||
|
||
// Close resource | ||
$b->close(); | ||
} | ||
|
||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Contributte\Application\Response\Fly\Buffer; | ||
|
||
interface Buffer | ||
{ | ||
|
||
const BLOCK = 8196; | ||
|
||
/** | ||
* @param mixed $data | ||
* @return void | ||
*/ | ||
public function write($data); | ||
|
||
/** | ||
* @param int $size | ||
* @return mixed | ||
*/ | ||
public function read($size); | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function eof(); | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function close(); | ||
|
||
} |
Oops, something went wrong.