【发布时间】:2021-06-15 11:45:56
【问题描述】:
我有文件夹/home/wira/wirdev/smscounter,
在那个文件夹中,我正在从https://github.com/instasent/sms-counter-php 安装短信计数器,安装完成。现在我的文件夹里面是这样的:
.
├── checkSMSSegment.php
├── composer.json
├── composer.lock
├── sms.txt
├── tesSMSLength.php
└── vendor
├── autoload.php
├── composer
│ ├── autoload_classmap.php
│ ├── autoload_namespaces.php
│ ├── autoload_psr4.php
│ ├── autoload_real.php
│ ├── autoload_static.php
│ ├── ClassLoader.php
│ ├── installed.json
│ └── LICENSE
└── instasent
└── sms-counter-php
├── composer.json
├── LICENSE-MIT
├── phpunit.xml.dist
├── README.md
├── SMSCounter.php
└── Tests
└── SMSCounterTest.php
这是我要运行的代码 (tesSMSLength.php):
<?php
use Instasent\SMSCounter\SMSCounter;
$text = file_get_contents(dirname(__FILE__)."/sms.txt");
$smsCounter = new SMSCounter();
$result = $smsCounter->count($text);
print_r($result);
现在我想通过键入 sudo php tesSMSLength.php 来使用这个库运行我的代码,但它显示 ERROR class not found 像这样:
[wira@DevWira smscounter]$ sudo php tesSMSLength.php
PHP Fatal error: Uncaught Error: Class 'Instasent\SMSCounter\SMSCounter' not found in /home/wira/wirdev/smscounter/tesSMSLength.php:6
Stack trace:
#0 {main}
thrown in /home/wira/wirdev/smscounter/tesSMSLength.php on line 6
我在这里缺少什么?
这是composer.json 内容:
{
"require": {
"instasent/sms-counter-php": "^0.4"
},
"autoload": {
"psr-4": {
"Instasent\\SMSCounter\\": ""
}
},
}
【问题讨论】:
-
您忘记将自动加载器导入到您的测试文件中
标签: php installation composer-php