本文整理汇总了PHP中Illuminate\Http\Response::header方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::header方法的具体用法?PHP Response::header怎么用?PHP Response::header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Response
的用法示例。
在下文中一共展示了Response::header方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getQr
public function getQr(Request $req)
{
$qrCode = new QrCode();
$qrCode->setText("http://10.0.20.55:8001/index/wel#/sys/activities/one")->setSize(300)->setPadding(10)->setErrorCorrection('high')->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0));
$response = new Response($qrCode->get(), 200);
$response->header('content-type', 'image/png');
return $response;
}
示例2: handle
public function handle($request, Closure $next)
{
$response = new Response();
if (Auth::check() === false) {
$request->request->set('roleId', $this->retrieveRoleIdByName('Customer'));
return $next($request);
}
$user = Auth::user();
if ($user === null) {
$response->header(Constants::RESPONSE_HEADER, "Failed to retrieve authenticated user.");
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
$role = Roles::where('id', $user->role_id)->firstOrFail();
if ($role->name !== "Administrator") {
$response->header(Constants::RESPONSE_HEADER, "Permission are required for performing registration operation.");
$response->setStatusCode(Response::HTTP_FORBIDDEN);
return $response;
}
try {
$roleName = $request->get('roleName');
if ($roleName === null) {
$request->request->set('roleId', $this->retrieveRoleIdByName('Customer'));
} else {
$request->request->set('roleId', $this->retrieveRoleIdByName($roleName));
}
} catch (Exception $exception) {
$response->header(Constants::RESPONSE_HEADER, $exception->getMessage());
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
return $response;
}
return $next($request);
}
示例3: addRateLimitToResponse
/**
* Add the RateLimit to the response cookies.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Response $response
* @return \Illuminate\Http\Response
*/
protected function addRateLimitToResponse($request, $response, $limit)
{
$throttle = $this->throttle->get($request);
$response->header('x-rate-limit-limit', $limit);
$response->header('x-rate-limit-remaining', $limit - $throttle->count());
return $response;
}
示例4: getResource
public function getResource(Request $request, Log $logger, $path)
{
// Get date metadata and calculate ETag
$timestamp = $this->fs->getTimestamp($path);
$ETag = md5($path . $timestamp);
$date = new DateTime("@{$timestamp}");
$response = new Response();
$response->setLastModified($date)->setEtag($ETag, true)->setPublic();
// Check modified date and Etag before attempting to retrieve actual content
if ($response->isNotModified($request)) {
return $response;
}
$content = $this->fs->read($path);
if (!$content) {
// We had a false positive from the cache!!
$this->deleteFromCache($path);
$logger->warning('File not found (cache false positive)', array('path' => $path));
abort(404);
}
$contentType = $this->fs->getMimetype($path);
if (env('EXAMPLE_DIR') && starts_with($path, env('EXAMPLE_DIR'))) {
// Path is within our "examples" directory, force the file to be downloaded
$disposition = $response->headers->makeDisposition(HeaderBag::DISPOSITION_ATTACHMENT, basename($path));
$response->header('Content-Disposition', $disposition);
}
return $response->header('Content-Type', $contentType)->setContent($content);
}
示例5: getImage
public function getImage($id, $hash, Request $request)
{
$entry = StorageEntry::findOrFail($id);
if ($hash != $entry->hash) {
abort(404);
}
$response = new Response($this->makeImage($entry, $request->has('w') ? $request->input('w') : null, $request->has('h') ? $request->input('h') : null), 200);
$response->header('Content-Type', $entry->mime);
$response->header('Cache-Control', 'max-age=86400');
return $response;
}
示例6: createUser
public function createUser(Request $request, Response $response)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$response->header(Constants::RESPONSE_HEADER, "Validation failed with the following error messages: [" . $validator->errors() . "].");
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
return $response;
}
$user = User::create(['email' => $request->input('email'), 'password' => bcrypt($request->input('password')), 'first_name' => $request->input('firstname'), 'last_name' => $request->input('lastname'), 'role_id' => $request->input('roleId'), 'object_name' => $request->input('objectName')]);
if ($user === null) {
$response->header(Constants::RESPONSE_HEADER, "Failed to create user.");
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
return $user;
}
示例7: newThread
/**
* New thread (not the create thread page)
* @param Request $request
* @return string
*/
public function newThread(Request $request)
{
// Validate input
$this->validate($request, ['title' => 'required|max:255', 'forum' => 'required|numeric', 'body' => 'required|max:30000']);
// Verify forum is a valid forum that can be posted in
$forum = null;
try {
$forum = Forum::findOrFail($request->input('forum'));
} catch (ModelNotFoundException $e) {
abort(400);
// 400 Bad Request - invalid forum id
}
if ($forum->type != 0) {
abort(400);
// 400 Bad Request - not correct forum type
}
// Create thread
$thread = Thread::newThread($request->input('title'), $request->input('forum'));
// Create opening post
$post = post::newPost($request->input('body'), $thread->id);
// Generate response
$resp = new Response(json_encode(['status' => true, 'link' => $thread->getUserFriendlyURL()]), 200);
$resp->header('Content-Type', 'application/json');
return $resp;
}
示例8: retrieveUserData
public function retrieveUserData(Request $request, Response $response)
{
if (Auth::check() === false) {
$response->header(Constants::RESPONSE_HEADER, "There is no authenticated user.");
$response->setStatusCode(Response::HTTP_NO_CONTENT);
return $response;
}
$user = Auth::user();
if ($user === null) {
$response->header(Constants::RESPONSE_HEADER, "There is no authenticated user.");
$response->setStatusCode(Response::HTTP_NO_CONTENT);
return $response;
}
Log::debug("Retrieved user data: [" . json_encode($user) . "]");
return $user;
}
示例9: postRegister
public function postRegister(Request $request)
{
$errors = [];
// Validate all fields have been received.
$validator = \Validator::make($request->all(), array('email' => 'required|email|max:128|unique:users,email', 'username' => 'required|min:1|max:20|unique:users,name', 'password' => 'required|min:6|max:255', 'g-recaptcha-response' => 'recaptcha'));
if ($validator->fails()) {
// Validator detected some problems.
foreach ($validator->errors()->getMessages() as $error) {
$errors[] = $error;
}
}
if (count($errors) > 0) {
// Errors detected, generate response
$response = new Response(json_encode(['status' => false, 'errors' => $errors]), 200);
$response->header('Content-Type', 'application/json');
return $response;
}
// Get input
$email = $request->input('email');
$username = $request->input('username');
$password = $request->input('password');
// Register user
$user = User::register($email, $username, $password);
// Login
Auth::login($user);
// Generate response
$response = new Response(json_encode(['status' => true]), 200);
$response->header('Content-Type', 'application/json');
return $response;
}
示例10: get_captcha_image
public function get_captcha_image()
{
$fname = Input::get('fname');
$content = file_get_contents($fname);
$response = new Response($content, 200);
$response->header('Content-Type', "image/png");
return $response;
}
示例11: createLocalResponse
/**
* Attempt to create local response type from guzzle response
*
* @param GuzzleResponse $guzzleResponse
*
* @return Response
*/
protected static function createLocalResponse(GuzzleResponse $guzzleResponse)
{
$response = new Response($guzzleResponse->getBody(), $guzzleResponse->getStatusCode());
$headers = $guzzleResponse->getHeaders();
array_walk($headers, function ($values, $name) use($response) {
$response->header($name, implode(', ', $values), true);
});
return $response;
}
示例12: findUserById
public function findUserById(Request $request, Response $response)
{
$validator = Validator::make($request->all(), ['id' => 'required|numeric']);
if ($validator->fails()) {
$response->header(Constants::RESPONSE_HEADER, "\"id\" query parameter is required and must contain number as value.");
$response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY);
return $response;
}
$id = $request->input("id");
$product = User::with('role')->find($id);
if ($product === null) {
$response->header(Constants::RESPONSE_HEADER, "User not found.");
$response->setStatusCode(Response::HTTP_NO_CONTENT);
return $response;
}
$response->header(Constants::RESPONSE_HEADER, "Successfully retrieved data.");
return $product;
}
示例13: notFoundResponse
protected function notFoundResponse()
{
if ($this->config['handler_404'] == 'default') {
abort(404);
} else {
$image = base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAP6UlEQVRoga06aVAc15lf9/QMAww3w31K3CBAIARCSDaSbGVjWyvbK6esxPFRqWxtVZLarUp5t1zZrP1jq3az+ZHKUZtUee1kfcmWrSO2bCeKRUwkWZaAcAqQkEAMMDADczADc/a8/d7r7qGHGVgk+VGP7vf6ve++Xvdw8BW1vuuXiudNtg7bkmuXZ9VbGxSDhSGR5AOQJLaA4+w8xy8IWn42Pj5+KC3d0J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9L6gc6248ePP/fOpozQ9sorr/x62jQX/tRGI0vnwzuhraOGMQbr3nQQuQTnlGfro3YsbARYdqZTVDNEvQYHQVGEv3QNoUUMqUp8AtvLSn720r+89E+wCehw6+rqEs59/OkndrvjkDJHGdjTUQcHHm7GI7EWNjh4bwCSRA85FdXhE6b00Ovxw/lPr8K1K2PhUoQ2ozH9T89865lHamujvyduWB+MjHQZXn31oz8su9zt6lheVVMCjxzpQKBpIIXU6LN9NAP//1sX2ZLBbLbCubMX6XcQVXFKIDU1+fILzz9/GJmI+elt00KHMvM/r310xul0H1TPp6YlwYOdu6G5pQ4dOB42bZu9cVGOh9hWVjxw5XI//OXzHnC5VlWLCGRkpJ1/9ttfe6K2tvPuP4YqbWRkRHfixIn/mjNbfhCxEZNFbm4m7Nm7C+obqiE1JTnijcpmTbEsWm07HMvQ3z8MX1zuA8uCTc7aCveYAgrzf7N///7vdXZ2BjeDueXS81e/+sU3+gdHfomVcWYEAIRAf9lQWVUOdXXViBhLG2RKq9Wy0KyYnfJhk36qszscMHVnGoYHR2BiYir6+zown3Tsaq75zne/+/0PtkLfXdXkXV0fZp775NJP7Tb7M8ByUKTdUI3o9XpITjLQww5jkP7qgTav1wvLyy7UgIO+r2UMkdgntBD63xuPPdr54t69hy1bpe1eDhfw5puv1VzrHX7Z7VqhHyWF2KvkWouoAtLmzh9MSTGcbGtt+slTT32z/25puidGlPbeh+/lD1wdet66sHRMDIn39DMnrCQGs3OMJ5sbK3939OjTJrjHdl+MqNs7Z94pnB6fPGBdcjSuuD0NwWAwHwtDI2ohjSHiOBd2s1YrzBoSEwaysow9pdW5F5985Jt37h87wP8BN8/KqbSj3wkAAAAASUVORK5CYII=');
$response = new Response($image, 404);
return $response->header('Content-Type', 'image/png');
}
}
示例14: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
// This step is only needed if you are returning
// a view in your Controller or elsewhere, because
// when returning a view `$next($request)` returns
// a View object, not a Response object, so we need
// to wrap the View back in a Response.
if (!$response instanceof SymfonyResponse) {
$response = new Response($response);
}
/**
* @var $headers \Symfony\Component\HttpFoundation\HeaderBag
*/
$response->header('Pragma', 'no-cache');
$response->header('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT');
$response->header('Cache-Control', 'no-cache, must-revalidate, no-store, max-age=0, private');
return $response;
}
示例15: sendResponse
/**
* @param Response $response
* @param string $mimeType
*/
protected function sendResponse(Response $response, $mimeType)
{
if (empty($mimeType)) {
$mimeType = 'text/html';
}
$response->header('Content-type', $mimeType);
$response->setStatusCode(404);
$response->send();
exit;
}