php - PHP 类使用 composer 中的其他类
问题描述
我制作了一个使用 psr-4 自动加载的类。在这堂课中,我想使用我用 composer 下载的一些库中的类,问题是我似乎无法弄清楚。班级:
<?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"]);
...
}
方法句柄是从电报 webhook 调用的,所以我不知道如何对其进行调试,但我 100% 确定当 Dotenv 尝试实例化时它会崩溃。树视图:
/CusTelegram
/CusCommand
/NewEpisodeCommand.php (this class)
/bot
/bot.php
/vendor
...
在 bot php 中,我已经需要自动加载。这个类没有问题,只是我不能在 NewEpisodeCommand 类中使用 DotEnv 和 ApiVideo。机器人.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-- 我能够打印错误,这就是我得到的:
Fatal error: Uncaught Error: Class 'CusTelegram\CusCommand\Dotenv\Dotenv' not found in /membri/streamapi/CusTelegram/CusCommand/NewEpisodeCommand.php
解决方案
我能够修复我只需要插入使用路径的错误,例如:
use Dotenv\Dotenv;
use ApiVideo\Client\Client;
推荐阅读
- oracle - 如何将用户定义的表类型作为参数传递给游标?
- php - Laravel API Post 返回登录屏幕
- ruby - 在 Ruby 中使用 creek 跳过读取 EXCEL 文件的第一行
- c# - 在部署时从 Azure 函数获取 Azure 函数密钥?
- javascript - 如何使用来自两个数组的键创建 JS 对象?
- python - 如何在 python 中将 xml 文件转换为数据框或 csv 输出
- python - 当我单击表单html中的按钮时如何执行脚本python?
- sql - SQL 不是 hard case 语句
- c# - 如何阻止cmd窗口关闭
- intellij-idea - 获取依赖项时 Dart SDK 版本错误