Estoy trabajando con un proyecto sencillo que incorpora autoload con composer, pero por alguna razon autoload no funciona correctamente y me lanza este error:
Fri Apr 9 23:03:22 2021] [::1]:40550 [500]: GET / - Uncaught Error: Class "Application\NuevaClase" not found in /home/angel/Escritorio/PruebaProyecto/includes/app.php:7
Stack trace:
#0 /home/angel/Escritorio/PruebaProyecto/index.php(12): require()
#1 {main}
thrown in /home/angel/Escritorio/PruebaProyecto/includes/app.php on line 7
Este es el arbol de mi proyecto:
Y aqui esta el código de los archivos que utilice:
PruebaAutp.php
<?php
namespace Application;
class NuevaClase{
}
?>
app.php
<?php
require 'funciones.php';
require __DIR__.'/../vendor/autoload.php';
use Application\NuevaClase;
$nuevo = new NuevaClase; //Al instaciar la clase se detona el error
var_dump($nuevo);
?>
funciones.php
<?php
define('TEMPLATE_URL',__DIR__.'/templates');
function insertTemplate(string $nombre):void{
include TEMPLATE_URL."/${nombre}.php";
}
?>
composer.json
{
"name": "angel/prueba-proyecto",
"authors": [
{
"name": "Angel",
"email": "[email protected]"
}
],
"require": {},
"autoload": {
"psr-4": {
"Application\\":"clases/"
}
}
}
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
require 'includes/app.php';
insertTemplate('header');
?>
</body>
</html>
header.php
<h1> Algun Texto </h1>
--------- Edición ---------
Renombrado el archivo: /clases/PruebaAuto.php Renombrando la clase:
namespace App;
class PruebaAuto{}
Error persiste:
Sat Apr 10 11:01:13 2021] [::1]:40100 [500]: GET / - Uncaught Error: Class "App\PruebaAuto" not found in /home/angel/Escritorio/PruebaProyecto/includes/app.php:7
Stack trace:
#0 /home/angel/Escritorio/PruebaProyecto/index.php(12): require()
#1 {main}
thrown in /home/angel/Escritorio/PruebaProyecto/includes/app.php on line 7