本文整理汇总了PHP中Sabre\HTTP\Sapi::sendResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Sapi::sendResponse方法的具体用法?PHP Sapi::sendResponse怎么用?PHP Sapi::sendResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\HTTP\Sapi
的用法示例。
在下文中一共展示了Sapi::sendResponse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticateHttpBasic
/**
* @static
* @throws \Exception
* @return User
*/
public static function authenticateHttpBasic()
{
// we're using Sabre\HTTP for basic auth
$request = \Sabre\HTTP\Sapi::getRequest();
$response = new \Sabre\HTTP\Response();
$auth = new \Sabre\HTTP\Auth\Basic(Tool::getHostname(), $request, $response);
$result = $auth->getCredentials();
if (is_array($result)) {
list($username, $password) = $result;
$user = self::authenticatePlaintext($username, $password);
if ($user) {
return $user;
}
}
$auth->requireLogin();
$response->setBody("Authentication required");
\Logger::error("Authentication Basic (WebDAV) required");
\Sabre\HTTP\Sapi::sendResponse($response);
die;
}
示例2: view
/**
* Sends compiled view
* @param string $tpl_name Name of the template (in "dot" notation)
* @param array $data Array containing your data; empty by default
* @param integer $status_code HTTP status code for the response; 200 by default
*/
function view($tpl_name, $data = [], $status_code = 200)
{
$response = new HTTP\Response();
$response->setStatus($status_code);
$response->setBody(twig()->render($tpl_name, $data));
HTTP\Sapi::sendResponse($response);
}
示例3: Response
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
$userList = ["user1" => "password", "user2" => "password"];
use Sabre\HTTP\Sapi;
use Sabre\HTTP\Response;
use Sabre\HTTP\Auth;
// Find the autoloader
$paths = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/vendor/autoload.php'];
foreach ($paths as $path) {
if (file_exists($path)) {
include $path;
break;
}
}
$request = Sapi::getRequest();
$response = new Response();
$basicAuth = new Auth\Basic("Locked down area", $request, $response);
if (!($userPass = $basicAuth->getCredentials())) {
// No username or password given
$basicAuth->requireLogin();
} elseif (!isset($userList[$userPass[0]]) || $userList[$userPass[0]] !== $userPass[1]) {
// Username or password are incorrect
$basicAuth->requireLogin();
} else {
// Success !
$response->setBody('You are logged in!');
}
// Sending the response
Sapi::sendResponse($response);
示例4: switch
$r->addRoute($route[0], $route[1], $route[2]);
}
};
$req = $request();
$dispatcher = \FastRoute\simpleDispatcher($routeDefinitionCallback);
$routeInfo = $dispatcher->dispatch($req->getMethod(), '/' . $req->getPath());
switch ($routeInfo[0]) {
case \FastRoute\Dispatcher::NOT_FOUND:
$resp = $response();
$resp->setBody('404 - Page not found');
$resp->setStatus(404);
\Sabre\HTTP\Sapi::sendResponse($resp);
exit;
break;
case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
$allowedMethods = $routeInfo[1];
$resp = $response();
$resp->setHeader('Allow', $allowedMethods);
$resp->setBody('405 - Method not allowed');
$resp->setStatus(405);
\Sabre\HTTP\Sapi::sendResponse($resp);
exit;
break;
case \FastRoute\Dispatcher::FOUND:
$className = $routeInfo[1][0];
$method = $routeInfo[1][1];
$vars = $routeInfo[2];
$class = $dic->make($className);
$class->{$method}($vars);
break;
}
示例5: showLoginForm
private function showLoginForm($auth, $response)
{
$auth->requireLogin();
$loginForm = new LoginForm($this->baseuri);
$response->setBody($loginForm->getBody());
HTTP\Sapi::sendResponse($response);
}
示例6: send
public function send()
{
\Sabre\HTTP\Sapi::sendResponse($this);
}
示例7: show
public function show()
{
$this->response->setBody('<h1>Hello World</h1>');
\Sabre\HTTP\Sapi::sendResponse($this->response);
}