0

I made a class which autoloads with psr-4. In this class I wanted to use classes from some libraries that I downloaded with composer the problem is that I can't seem to figure it out. Class:

<?php
namespace CusTelegram\CusCommand; 
use Telegram\Bot\Actions;
use Telegram\Bot\Commands\Command;
class NewEpisodeCommand extends Command
{
    public function handle($arguments)
    { 
        ...
        $dotenv = new Dotenv\Dotenv(__DIR__ . "/../..");
        $this->replyWithMessage(['text' => __DIR__ . "/../.."]);
        $dotenv->overload();
        $client = new ApiVideo\Client\Client($_ENV["API_EMAIL"], $_ENV["API_KEY"]);
        ...
}

The method handle gets called from a telegram webhook so I don't know how to degub it but I'm 100% sure that it crashes when Dotenv tries to get instanciated. Tree view:

/CusTelegram
  /CusCommand
    /NewEpisodeCommand.php (this class)
/bot
  /bot.php
/vendor
...

In bot php I already require the autoload. This class doesn't have issues is just that I can't use DotEnv and ApiVideo in the NewEpisodeCommand class. Bot.php:

ini_set('memory_limit', '-1');
require_once '../vendor/autoload.php';

use Telegram\Bot\Api;
$telegram = new Api(<token>);
$commands = [CusTelegram\CusCommand\StartCommand::class, CusTelegram\CusCommand\NewEpisodeCommand::class, Telegram\Bot\Commands\HelpCommand::class ];
$telegram->addCommands($commands);

$update = $telegram->commandsHandler(true);

--EDIT-- I was able to print the error and this is what I get:

Fatal error: Uncaught Error: Class 'CusTelegram\CusCommand\Dotenv\Dotenv' not found in /membri/streamapi/CusTelegram/CusCommand/NewEpisodeCommand.php
Leonardo Drici
  • 749
  • 3
  • 11
  • 32

1 Answers1

1

I was able to fix the error I just needed to insert the use path like:

use Dotenv\Dotenv;
use ApiVideo\Client\Client;
Leonardo Drici
  • 749
  • 3
  • 11
  • 32
  • 1
    If you didn't want to use the `use` statement, you would have to prefix the FQCN with a backslash like this: `$dotenv = new \Dotenv\Dotenv(__DIR__ . "/../..");` – xabbuh Nov 20 '18 at 11:24