Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: Have a routes collection interface & support in Tracy router panel #94

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added CallbackResponse
  • Loading branch information
dg committed Sep 30, 2015
commit 6e8dbd3ae14e3d8ce8d08b1153d069d32f232ddc
37 changes: 37 additions & 0 deletions src/Application/Responses/CallbackResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* This file is part of the Nette Framework (http://nette.org)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Application\Responses;

use Nette;


/**
* Callback response.
*/
class CallbackResponse extends Nette\Object implements Nette\Application\IResponse
{
/** @var callable */
private $callback;


public function __construct(callable $callback)
{
$this->callback = $callback;
}


/**
* Sends response to output.
* @return void
*/
public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
{
call_user_func($this->callback, $httpRequest, $httpResponse);
}

}
21 changes: 21 additions & 0 deletions tests/Application/CallbackResponse.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* Test: Nette\Application\Responses\CallbackResponse.
*/

use Nette\Application\Responses\CallbackResponse;
use Nette\Http;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


test(function () {
$response = new CallbackResponse(function (Http\IRequest $request, Http\IResponse $response) use (& $ok) {
$ok = TRUE;
});
$response->send(new Http\Request(new Http\UrlScript), new Http\Response);
Assert::true($ok);
});