本文整理匯總了PHP中Slim\App::respond方法的典型用法代碼示例。如果您正苦於以下問題:PHP App::respond方法的具體用法?PHP App::respond怎麽用?PHP App::respond使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Slim\App
的用法示例。
在下文中一共展示了App::respond方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: renderResponse
/**
* @param ResponseInterface $response
*/
private function renderResponse(ResponseInterface $response)
{
if ($this->slim) {
$this->slim->respond($response);
} else {
// do something
}
}
示例2: testRespondNoContent
/**
* @runInSeparateProcess
*/
public function testRespondNoContent()
{
$app = new App();
$app->get('/foo', function ($req, $res) {
$res = $res->withStatus(204);
return $res;
});
// Prepare request and response objects
$env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET']);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new Body(fopen('php://temp', 'r+'));
$req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$res = new Response();
// Invoke app
$resOut = $app($req, $res);
$app->respond($resOut);
$this->assertInstanceOf('\\Psr\\Http\\Message\\ResponseInterface', $resOut);
$this->assertEquals([], $resOut->getHeader('Content-Type'));
$this->assertEquals([], $resOut->getHeader('Content-Length'));
$this->expectOutputString('');
}
示例3: testRespondWithPaddedStreamFilterOutput
/**
* @runInSeparateProcess
*/
public function testRespondWithPaddedStreamFilterOutput()
{
$availableFilter = stream_get_filters();
if (in_array('mcrypt.*', $availableFilter) && in_array('mdecrypt.*', $availableFilter)) {
$app = new App();
$app->get('/foo', function ($req, $res) {
$key = base64_decode('xxxxxxxxxxxxxxxx');
$iv = base64_decode('Z6wNDk9LogWI4HYlRu0mng==');
$data = 'Hello';
$length = strlen($data);
$stream = fopen('php://temp', 'r+');
$filter = stream_filter_append($stream, 'mcrypt.rijndael-128', STREAM_FILTER_WRITE, ['key' => $key, 'iv' => $iv]);
fwrite($stream, $data);
rewind($stream);
stream_filter_remove($filter);
stream_filter_append($stream, 'mdecrypt.rijndael-128', STREAM_FILTER_READ, ['key' => $key, 'iv' => $iv]);
return $res->withHeader('Content-Length', $length)->withBody(new Body($stream));
});
// Prepare request and response objects
$env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET']);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new RequestBody();
$req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$res = new Response();
// Invoke app
$resOut = $app($req, $res);
$app->respond($resOut);
$this->assertInstanceOf('\\Psr\\Http\\Message\\ResponseInterface', $resOut);
$this->expectOutputString('Hello');
} else {
$this->assertTrue(true);
}
}
示例4: dispatchResponse
private function dispatchResponse(ResponseInterface $response)
{
$this->slimApp->respond($response);
}