Componette

Componette

contributte

contributte / fly-response v0.2

๐Ÿ’€ [DISCONTINUED] Serve data and files on-the-fly as response to Nette Framework (@nette). Use contributte/application.

download-cloud-line composer require minetro/fly-response

Website ๐Ÿš€ contributte.org | Contact ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป f3l1x.io | Twitter ๐Ÿฆ @contributte

Disclaimer

โš ๏ธ This project is no longer being maintained. Please use contributte/application.
Composer minetro/fly-response
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.

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);
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);
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);

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()
		);
	}
}

Development

This package was maintain by these authors.


Consider to support contributte development team. Also thank you for being used this package.

  • v0.2 v0.2

    ๐Ÿ”ช Bump!

    Changes:

    • unlock for nette ~2.4.0
    • sophisticated version testing
  • v0.1 v0.1

    First release!

bar-chart-fill

Statistics

download-cloud-fill
2487
star-fill
6
bug-fill
0
flashlight-fill
47d
price-tag-2-line

Badges

guide-fill

Dependencies

php (>= 5.5)
nette/application (~2.3.0|~2.4.0)
nette/http (~2.3.0|~2.4.0)
Componette Componette felix@nette.org