Apos tentar seguir os passos da aula 4 (Setimo Tópico), o servidor não reconhece a instancia da interface:
127.0.0.1:55132 [500]: GET /novo-curso - Uncaught TypeError: Argument 1 passed to Alura\Cursos\Controller\FormularioInsercao::processaRequisicao() must be an instance of Alura\Cursos\Controller\ServerInterface, instance of Nyholm\Psr7\ServerRequest given, called in /var/www/html/phpmvc/psrs/public/index.php on line 39 and defined in /var/www/html/phpmvc/psrs/src/Controller/FormularioInsercao.php:12 Stack trace:
#0 /var/www/html/phpmvc/psrs/public/index.php(39): Alura\Cursos\Controller\FormularioInsercao->processaRequisicao()
#1 {main} thrown in /var/www/html/phpmvc/psrs/src/Controller/FormularioInsercao.php on line 12
Segui todos os padrões e não retornaram erro da Psr7, vou deixar as classes abaixo, pois eu não encontrei erro; Estou usando Ubuntu Ubuntu 20.04.2 LTS
(Index)
` <?php
require DIR. '/../vendor/autoload.php';
use Alura\Cursos\Controller\InterfaceControladorRequisicao; use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7Server\ServerRequestCreator;
$caminho = $SERVER['PATHINFO']; $rotas = require DIR . '/../config/routes.php';
if(!array_key_exists($caminho,$rotas)){ http_response_code(404);}
session_start();
$psr17Factory = new Psr17Factory();
$creator = new ServerRequestCreator( $psr17Factory, // ServerRequestFactory $psr17Factory, // UriFactory $psr17Factory, // UploadedFileFactory $psr17Factory // StreamFactory );
$request = $creator->fromGlobals();
$classeControladora = $rotas[$caminho]; $controlador = new $classeControladora(); $resposta = $controlador->processaRequisicao($request);
foreach($resposta->getHeaders() as $name => $values){ foreach($values as $value){ header(sprintf('%s: %s',$name,$value),false); } }
echo $resposta->getBody();
`
(Interface)
` <?php
namespace Alura\Cursos\Controller;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;
interface InterfaceControladorRequisicao { public function processaRequisicao(ServerInterface $request):ResponseInterface; }
?> `
(FormularioInsercao) ` <?php
namespace Alura\Cursos\Controller;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class FormularioInsercao implements InterfaceControladorRequisicao
{
public function processaRequisicao(ServerInterface $request):ResponseInterface
{
$html = 'Teste';
return new Response(200,[],$html);
}
}
?>
`
(routes)
` <?php
use Alura\Cursos\Controller\FormularioInsercao;
return [
'/novo-curso' => FormularioInsercao::class,
];
?> `