Contributte Fly-response

Website 🚀 contributte.org | Contact 👨🏻‍💻 f3l1x.io | Twitter 🐦 @contributte

# Disclaimer

⚠️ This project is no longer being maintained. Please use contributte/application (opens new window).
Composer minetro/fly-response (opens new window)
Version
PHP
License

# Documentation

# Usage

# Responses

# FlyResponse

For common purpose and your custom solutions.

# FlyFileResponse

Special response for handling files on-the-fly.

# Adapters

# ProcessAdapter

Execute command over popen (opens new window).

use Minetro\FlyResponse\Adapter\ProcessAdapter;
use Minetro\FlyResponse\FlyFileResponse;

// Compress current folder and send to response
$adapter = new ProcessAdapter('tar cf - ./ | gzip -c -f');
$response = new FlyFileResponse($adapter, 'folder.tgz');

$this->sendResponse($response);
1
2
3
4
5
6
7
8
# StdoutAdapter

Write to php://output.

use Minetro\FlyResponse\Adapter\StdoutAdapter;
use Minetro\FlyResponse\Buffer\Buffer;
use Minetro\FlyResponse\FlyFileResponse;
use Nette\Http\IRequest;
use Nette\Http\IResponse;

// Write to stdout over buffer class
$adapter = new StdoutAdapter(function(Buffer $buffer, IRequest $request, IResponse $response) {
	// Modify headers
	$response->setHeader(..);

	// Write data
	$buffer->write('Some data..');
});
$response = new FlyFileResponse($adapter, 'my.data');

$this->sendResponse($response);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# CallbackAdapter
use Minetro\FlyResponse\Adapter\CallbackAdapter;
use Minetro\FlyResponse\Buffer\Buffer;
use Minetro\FlyResponse\FlyFileResponse;
use Nette\Http\IRequest;
use Nette\Http\IResponse;

$adapter = new CallbackAdapter(function(IRequest $request, IResponse $response) use ($model) {
	// Modify headers
	$response->setHeader($header);

	// Fetch topsecret data
	$data = $this->facade->getData();
	foreach ($data as $d) {
		// Write or print data..
	}
});
$response = new FlyFileResponse($adapter, 'my.data');

$this->sendResponse($response);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# Model

final class BigOperationHandler
{

	/** @var Facade */
	private $facade;

	/**
	 * @param Facade $facade
	 */
	public function __construct(Facade $facade)
	{
		$this->facade = $facade;
	}

	public function toFlyResponse()
	{
		$adapter = new CallbackAdapter(function (IRequest $request, IResponse $response) {
			// Modify headers
			$response->setHeader(..);

			// Fetch topsecret data
			$data = $this->facade->getData();
			foreach ($data as $d) {
				// Write or print data..
			}
		});

		return new FlyFileResponse($adapter, 'file.ext');

		// or
		return new FlyResponse($adapter);
	}
}

interface IBigOperationHandlerFactory
{

	/**
	 * @return BigOperationHandler
	 */
	public function create();

}

final class MyPresenter extends Nette\Application\UI\Presenter
{

	/** @var IBigOperationHandlerFactory @inject */
	public $bigOperationHandlerFactory;

	public function handleMagic()
	{
		$this->sendResponse(
			$this->bigOperationHandlerFactory->create()->toFlyResponse()
		);
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

# Development

This package was maintain by these authors.


Consider to support (opens new window) contributte development team. Also thank you for being used this package.