人人人妻人人人妻人人人,99精品国产综合久久久久五月天 ,欧美白人最猛性XXXXX,日韩AV无码免费播放

News新聞

業(yè)界新聞動(dòng)態(tài)、技術(shù)前沿
Who are we?

您的位置:首頁      樂道系統(tǒng)FAQ      Laravel 5.5中為響應(yīng)請求提供的可響應(yīng)接口詳解

Laravel 5.5中為響應(yīng)請求提供的可響應(yīng)接口詳解

標(biāo)簽: 發(fā)布日期:2017-11-30 00:00:00 316

前言

Laravel 5.5 也將會(huì)是接下來的一個(gè) LTS(長期支持)版本。 這就意味著它擁有兩年修復(fù)以及三年的安全更新支持。Laravel 5.1 也是如此,不過它兩年的錯(cuò)誤修復(fù)支持將在今年結(jié)束。

Laravel 5.5 的路由中增加了一種新的返回類型:可相應(yīng)接口( Responsable )。該接口允許對象在從控制器或者閉包路由中返回時(shí)自動(dòng)被轉(zhuǎn)化為標(biāo)準(zhǔn)的 HTTP 響應(yīng)接口。任何實(shí)現(xiàn) Responsable 接口的對象必須實(shí)現(xiàn)一個(gè)名為 toResponse() 的方法,該方法將對象轉(zhuǎn)化為 HTTP 響應(yīng)對象。

看示例:

use Illuminate\Contracts\Support\Responsable;

class ExampleObject implements Responsable
{
 public function __construct($name = null)
 {
  $this->name = $name ?? 'Teapot'; 
 }

 public function status()
 {
  switch(strtolower($this->name)) {
   case 'teapot':
    return 418;
   default:
    return 200;
  }
 }

 public function toResponse()
 {
  return response(
   "Hello {$this->name}",
   $this->status(),
   ['X-Person' => $this->name]
  );
 }
}