Olá, tenho o seguinte erro ao tentar alcançar o http://localhost:8088/novo-curso:
[Thu May 19 20:08:59 2022] PHP Fatal error: Could not check compatibility between Alura\Curso\Controller\FormularioInsercao::processaRequisicao(Psr\Http\Message\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface and Alura\Cursos\Controller\InterfaceControladorRequisicao::processaRequisicao(Alura\Cursos\Controller\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface, because class Alura\Cursos\Controller\ServerRequestInterface is not available in /home/helio/Documentos/PHP_Alura/php-mvc/psrs/src/Controller/FormularioInsercao.php on line 12 [Thu May 19 20:08:59 2022] 127.0.0.1:36564 [500]: GET /novo-curso - Could not check compatibility between Alura\Curso\Controller\FormularioInsercao::processaRequisicao(Psr\Http\Message\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface and Alura\Cursos\Controller\InterfaceControladorRequisicao::processaRequisicao(Alura\Cursos\Controller\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface, because class Alura\Cursos\Controller\ServerRequestInterface is not available in /home/helio/Documentos/PHP_Alura/php-mvc/psrs/src/Controller/FormularioInsercao.php on line 12 [Thu May 19 20:08:59 2022] 127.0.0.1:36564 Closing
Abaixo como estão meus arquivos:
InterfaceControladorRequisicao.php
<?php
namespace Alura\Cursos\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerResquestInterface;
interface InterfaceControladorRequisicao
{
public function processaRequisicao(ServerRequestInterface $request):ResponseInterface;
}
FormularioInsercao.php
<?php
namespace Alura\Curso\Controller;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Alura\Cursos\Controller\InterfaceControladorRequisicao;
class FormularioInsercao implements InterfaceControladorRequisicao
{
public function processaRequisicao (ServerRequestInterface $request): ResponseInterface
{
$html = 'Teste';
return new Response(200, [], $html);
}
}
routes.php
<?php
use Alura\Cursos\Controller\FormularioInsercao;
return [
'/novo-curso' => FormularioInsercao::class
];
index.php
<?php
require __DIR__ . '/../vendor/autoload.php';
use Alura\Cursos\Controller\InterfaceControladorRequisicao;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7Server\ServerRequestCreator;
$caminho = $_SERVER['PATH_INFO'];
$rotas = require __DIR__ . '/../config/routes.php';
if(!array_key_exists($caminho, $rotas)){
http_response_code(404);
exit();
}
session_start();
// $ehRotaDeLogin = stripos($caminho, 'login');
// if (!isset($_SESSION['logado']) && $ehRotaDeLogin === false) {
// header('Location: /login');
// exit();
// }
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
$creator = new \Nyholm\Psr7Server\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();