PRS-4 - Why does Class 'App\\TgHelpers\\TelegramCommandsProcess' not found?

72 Views Asked by At

The structure of my project is as follows:

enter image description here

Handler.php is input script. Here is its beginning:

require "vendor/autoload.php";
use \App\TgHelpers\TelegramCommandsProcess;
$tgProcessor = new TelegramCommandsProcess();

All scripts are in the same namespace - App. An error is displayed in the logs:

PHP Fatal error:  Uncaught Error: Class 'App\\TgHelpers\\TelegramCommandsProcess' not found

What am I doing wrong?

Here is the autoload field in composer.json:

"autoload": {
    "psr-4": {
        "App\\": "testVersionTelegramForecast//"
    }
 }
1

There are 1 best solutions below

4
On

the register must match \App\TgHelpers\ => project/TgHelpers,

composer.json should be at the root of your project

project/
   tgHelpers/
      TelegramCommandsProcess.php
   Handler.php
composer.json
vendor/
      autoload.php

In Handler.php

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