第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Slim 框架提供了一個(gè)令人困惑的未捕獲類型錯(cuò)誤

Slim 框架提供了一個(gè)令人困惑的未捕獲類型錯(cuò)誤

PHP
慕工程0101907 2021-12-24 15:05:26
我剛剛使用我自己的設(shè)置通過(guò) composer 安裝了一個(gè)新的 slim 副本。非常簡(jiǎn)單的 index.php,里面的內(nèi)容很少:<?phpuse Psr\Http\Message\ResponseInterface as Response;use Psr\Http\Message\ServerRequestInterface as Request;use Slim\Factory\AppFactory;require_once __DIR__ . '/../bootstrap.php';// start the app$APP = AppFactory::create();/** * Middleware to check validation before any routes */$APP->add(function(Request $request, Response $response, callable $next){    $response = $next($request,$response);    return $response;});/** * Add routes */$APP->get('/test',function(Request $request, Response $response, array $args){    return $response->getBody()->write('hello');});// run the app$APP->run();PHP給出了一個(gè)非常奇怪的錯(cuò)誤:**致命錯(cuò)誤:未捕獲的類型錯(cuò)誤:傳遞給 {closure}() 的參數(shù) 2 必須是 Psr\Http\Message\ResponseInterface 的實(shí)例,給出的 Slim\Routing\RouteRunner 實(shí)例,在 /var/www/vendor/slim/ 中調(diào)用slim/Slim/MiddlewareDispatcher.php 位于第 275 行,定義在 /var/www/public/index.php:16 堆棧跟蹤:#0 /var/www/vendor/slim/slim/Slim/MiddlewareDispatcher.php(275): {closure}(對(duì)象(Slim\Psr7\Request),對(duì)象(Slim\Routing\RouteRunner))1 /var/www/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): class@anonymous->handle(Object(Slim\Psr7\Request)) #2/var/www/vendor/slim/slim/Slim/App.php(206): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request)) #3 /var/www/vendor/slim/slim/Slim /App.php(190): Slim\App->handle(Object(Slim\Psr7\Request)) #4 /var/www/public/index.php(34): Slim\App->run() #5 {main} 在第 16 行的 /var/www/public/index.php 中拋出**我不明白為什么它說(shuō)這里的基本中間件正在使用 Slim\Routing\RouteRunner 的實(shí)例,而我顯然給了它 Psr\Http\Message\ResponseInterface任何的想法?編輯:感謝delboy的回答,但你能更具體點(diǎn)嗎?苗條的文檔顯示像這樣使用它(http://www.slimframework.com/docs/v3/concepts/middleware.html):$app->add(function ($request, $response, $next) {    $response->getBody()->write('BEFORE');    $response = $next($request, $response);    $response->getBody()->write('AFTER');    return $response;});但這不起作用!總是得到類型錯(cuò)誤,那么他們的文檔是否過(guò)時(shí)了?如果是這樣,我如何在這里實(shí)現(xiàn)中間件?我的示例代碼傳遞了 3 個(gè)參數(shù),而不是 2 個(gè)!
查看完整描述

3 回答

?
MM們

TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊

您的中間件沒(méi)有實(shí)現(xiàn) PSR-15。您不應(yīng)該傳遞響應(yīng),而是傳遞請(qǐng)求處理程序接口:


namespace Psr\Http\Server;


use Psr\Http\Message\ResponseInterface;

use Psr\Http\Message\ServerRequestInterface;


/**

 * Participant in processing a server request and response.

 *

 * An HTTP middleware component participates in processing an HTTP message:

 * by acting on the request, generating the response, or forwarding the

 * request to a subsequent middleware and possibly acting on its response.

 */

interface MiddlewareInterface

{

    /**

     * Process an incoming server request.

     *

     * Processes an incoming server request in order to produce a response.

     * If unable to produce the response itself, it may delegate to the provided

     * request handler to do so.

     */

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;

}

https://www.php-fig.org/psr/psr-15/


查看完整回答
反對(duì) 回復(fù) 2021-12-24
?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

需要添加:使用Slim\Psr7\Response;


查看完整回答
反對(duì) 回復(fù) 2021-12-24
?
蝴蝶不菲

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

首先,您需要檢查您使用的是哪個(gè)超薄版本,當(dāng)我開(kāi)始學(xué)習(xí)時(shí),我也遇到了這個(gè)錯(cuò)誤/問(wèn)題,但您想解決這個(gè)問(wèn)題,您可以在您的代碼中進(jìn)行此編輯。


$APP = AppFactory::create();

$app->setBasePath("/myapp/public/index.php");


$APP->add(function(Request $request, Response $response, callable $next){

    $response = $next($request,$response);

    return $response;

});


查看完整回答
反對(duì) 回復(fù) 2021-12-24
  • 3 回答
  • 0 關(guān)注
  • 153 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)