Problem with class referenced! " Fatal error: Class [...] not found in..."

Asked

Viewed 35 times

0

Good morning, folks. I am developing a login system (MVC) and tracking on youtube. The following error appears:

Error to find the class

I reviewed the code and couldn’t find the cause. Please, I would like someone to help me with this. Here is the repository and its files, with their codes:

Note: The "Support" folder is empty.

Repository and Files

php controller.

    <?php

namespace source\Controllers;

use CoffeeCode\Optimizer\Optimizer;
use CoffeeCode\Router\Router;
use League\Plates\Engine;

/**
 * Class controller
 * @package Source/Controllers
 */
abstract class controller
{
    /** 
    *@var Engine
    */
    protected $view;

    /** 
    *@var Router
    */
    protected $router;
    
    /**
    *@var Optimizer
    */
    protected $seo;

    /**
     * controller constructor
     * @param $router
     */
    public function __construct($router)
    {
        $this->router = $router;
        $this->view = Engine::create(dirname(__DIR__, 2) . "/views", "php");
        $this->view->addData(["router"=>$this->router]);
        
        $this->seo = new Optimizer();
        $this->seo->openGraph(site("name"),site("locale"),"article")
            ->publisher(SOCIAL["facebook_page"],SOCIAL["facebook_author"])
            ->twitterCard(SOCIAL["twitter_creator"],SOCIAL["twitter_site"],site("domain"))
            ->facebook(SOCIAL["facebook_appId"]);
    }
    /**
     * @param string $param
     * @param array $values
     * @return string
     */

    public function ajaxResponse(string $param, array $values): string
    {
        return json_encode([$param=>$values]);
    }
}

web php.

<?php

namespace source\Controllers;

Class Web extends controller
{
    public function __construct($router)
    {
        parent::__construct($router);

        if(!empty($_SESSION["user"])){
        $this->router->redirect("app.home");
        }
    }

    public function login(): void
    {
        echo "<h1> Olá mundo!</h1>";
    }
}

config.php

<?php
/*
    SITE CONFIG
*/
define("SITE",[
    "name" => "Auth em MVC com PHP",
    "desc" => "Aprenda a construir uma aplicação...",
    "domain" => "localauthes.com",
    "locale" => "pt_BR",
    "root" => "http://localhost/login"
]);
/*
    SITE MINIFY
*/
    if($_SERVER["SERVER_NAME"] == "localhost"){
        require __DIR__ . "/Minify.php";
    }

/*
    DATABASE DATALAYER
*/
    define("DATA_LAYER_CONFIG", [
        "driver" => "mysql",
        "host" => "localhost",
        "port" => "3306",
        "dbname" => "teste_login",
        "username" => "root",
        "passwd" => "",
        "options" => [
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
            PDO::ATTR_CASE => PDO::CASE_NATURAL
        ]
    ]);

    /*
    SOCIAL CONFIG
    */
    define("SOCIAL", [
    "facebook_page" => "TheKnightClash",
    "facebook_author" => "rodolfofernandes25",
    "facebook_appId" => "",
    "twitter_creator" => "@rft2507",
    "twitter_site" => "@rft2507"
    ]);

    /*
    *   MAIL CONNECT
    */

    define("MAIL", []);

    /*
    *   SOCIAL LOGIN: FACEBOOK_LOGIN
    */

    define("FACEBOOK_LOGIN", []);

    /*
    *   SOCIAL LOGIN: GOOGLE_LOGIN
    */

    define("GOOGLE_LOGIN", []);

php helpers.

<?php
    /** 
     * @param string|null $param
     * @return string
    */
     
    function site(string $param = null): string
    {
        if($param && !empty(SITE[$param])){
            return SITE[$param];
        }

        return SITE["root"];
    }

    /** 
     * @param string $path
     * @return string
    */

    function asset(string $path): string
    {
        return SITE["root"] . "/views/assets/{$path}";
    }

    function flash(string $type = null, string $message = null): ?string
    {
        if ($type && $message){
            $_SESSION["flash"] = [
                "type" => $type,
                "message" => $message
            ];

            return null;
        }

        if(!empty($_SESSION["flash"]) && $flash = $_SESSION["flash"]){
            unset($_SESSION["flash"]);
            return "<div class=\"message {$flash["type"]}\">{$flash["message"]}</div>";
        }

        return null;
    }

Composer.json

{
    "name": "rodsfer25/authphp",
    "description": "Uma simples peça de login para o seu quebra-cabeças, código aberto :)",
    "minimum-stability": "stable",
    "license": "MIT",
    "authors": [
        {
            "name": "Rodolfo Fernandes R de O Torres",
            "email": "[email protected]",
            "role": "Developer",
            "homepage": "https://github.com/RodsFer25"
        }
    ],
    "autoload": {
        "psr-4": {
            "Source\\": "source"
        },
        "files": [
            "source/config.php",
            "source/helpers.php"
        ]
    },
    "require": {
        "php": "^5.6 || ^7.0 || ^8.0",
        "ext-json": "*",
        "coffeecode/router": "1.0.7",
        "coffeecode/datalayer": "1.1.4",
        "coffeecode/optimizer": "2.0.0",
        "phpmailer/phpmailer": "6.1.4",
        "league/plates": "v4.0.0-alpha",
        "league/oauth2-facebook": "2.0.1",
        "league/oauth2-google": "3.0.2",
        "matthiasmullie/minify": "1.3.61"
    }
}

index php.

<?php

ob_start();
session_start();
//router recebe parâmetro e dispara uma rota que comunica com controlador e
//com método
require __DIR__ . "/vendor/autoload.php";

use CoffeeCode\Router\Router;

$router = new Router(site());
$router->namespace("source\Controllers");

/**
 * SITE
 */

 $router->group(null);
 $router->get("/","Web:login","web.login");
 $router->get("/cadastrar","Web:register","web.register");
 $router->get("/recuperar","Web:forget","web.forget");
 $router->get("/senha/{email}/{forget}","Web:reset","web.reset");


/**
 * AUTH
 */

/**
 * AUTH SOCIAL
 */

/**
 * PROFILE
 */

 /**
 * ERRORS
 */
$router->group("ops");
$router->get("/{errcode}","Web:error","web.error");
/**
 * ROUTE PROCESS
 */
$router->dispatch();
/* *
 * ERRORs PROCESS
 */
if($router->error()){
    $router->redirect("web.error",["errcode" => $router->error()]);
}
ob_end_flush();
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.