Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

PHP Fatal error: Uncaught Error: Class

Após a codificação do controller, o PHP não encontra o mesmo apesar da definição do namespace estar correta, segue os códigos:

index.php

<?php

use Alura\Mvc\Controller\VideoListController;

require_once __DIR__ . '/../vendor/autoload.php';

if (!array_key_exists('PATH_INFO', $_SERVER) || $_SERVER['PATH_INFO'] === '/') {
    $controller = new VideoListController();
    $controller->processaRequisicao();

} elseif ($_SERVER['PATH_INFO'] === '/novoVideo') {
    if($_SERVER['REQUEST_METHOD'] === 'GET') {
        require_once __DIR__ . '/../formulario.php';
    } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
        require_once __DIR__ . '/../novoVideo.php';
    }
} elseif ($_SERVER['PATH_INFO'] === '/editarVideo') {
    if($_SERVER['REQUEST_METHOD'] === 'GET') {
        require_once __DIR__ . '/../formulario.php';
    } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
        require_once __DIR__ . '/../editarVideo.php';
    }
} elseif($_SERVER['PATH_INFO'] === '/removerVideo') {
    require_once __DIR__ . '/../removerVideo.php';
}

VideoListController.php

<?php

namespace Alura\Mvc\Controller;

use Alura\Mvc\Repository\VideoRepository;
use PDO;

class VideoListController {

    private VideoRepository $videoRepository;

    public function __construct()
    {
        $pdo = new PDO('pgsql:host=localhost;port=5432;dbname=aluraPlay;user=postgres;password=post123');
        $this->videoRepository = new VideoRepository($pdo);
    }
    public function processaRequisicao(): array {
        return $videoList = $this->videoRepository->all();

        require_once 'inicio-html.php'; ?>
        <ul class="videos__container" alt="videos alura">
            <?php foreach ($videoList as $video) { ?>
            <li class="videos__item">
                <iframe width="100%" height="72%" src="<?php echo $video->url;?>"
                    title="YouTube video player" frameborder="0"
                    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                    allowfullscreen></iframe>
                <div class="descricao-video">
                    <img src="./img/logo.png" alt="logo canal alura">
                    <h3><?php echo $video->title;?></h3>
                    <div class="acoes-video">
                        <a href="./editarVideo?id=<?php echo $video->id;?>">Editar</a>
                        <a href="./removerVideo?id=<?php echo $video->id;?>">Excluir</a>
                    </div>
                </div>
            </li>
            <?php } ?>
        </ul>
    <?php require_once 'fim-html.php';
    }
}

Erro:

PHP Fatal error:  Uncaught Error: Class "Alura\Mvc\Controller\VideoListController" not found in C:\Users\Gabriel\Desktop\aluraPlay\public\index.php:8
Stack trace:
#0 {main}
  thrown in C:\Users\Gabriel\Desktop\aluraPlay\public\index.php on line 8

Fatal error: Uncaught Error: Class "Alura\Mvc\Controller\VideoListController" not found in C:\Users\Gabriel\Desktop\aluraPlay\public\index.php:8
Stack trace:
#0 {main}
  thrown in C:\Users\Gabriel\Desktop\aluraPlay\public\index.php on line 8

Estrutura:

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

1 resposta
solução!

Faltava colocar o ".php" no final do arquivo :/