本文整理汇总了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);
}