[英]PHP class use other classes from composer
I made a class which autoloads with psr-4. 我制作了一个使用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.
在本课程中,我想使用通过composer下载的某些库中的类,问题是我似乎无法弄清楚。 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. 方法句柄是从电报Webhook调用的,所以我不知道如何对其进行脱胶,但是我100%确信当Dotenv试图实例化时它会崩溃。 Tree view:
树视图:
/CusTelegram
/CusCommand
/NewEpisodeCommand.php (this class)
/bot
/bot.php
/vendor
...
In bot php I already require the autoload. 在bot php中,我已经需要自动加载。 This class doesn't have issues is just that I can't use DotEnv and ApiVideo in the NewEpisodeCommand class.
这个类没有问题,只是我不能在NewEpisodeCommand类中使用DotEnv和ApiVideo。 Bot.php:
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
I was able to fix the error I just needed to insert the use path like: 我能够解决我只需要插入如下使用路径的错误:
use Dotenv\Dotenv;
use ApiVideo\Client\Client;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.