![](/img/trans.png)
[英]Fatal error: Class 'Symfony\Component\Console\Input\ArgvInput' not found in app/console on line 16
[英]Symfony: Fatal Error: Class not found in app/console
我正在尝试从命令行获取命令以使用symfony进行工作。 我具有以下文件夹结构:
现在在我的控制台文件中,我有以下代码:
#!/usr/bin/env php
<?php
require_once '/../vendor/autoload.php';
use Source\Commands\TwitterCommand;
use Symfony\Component\Console\Application;
use Endroid\Twitter\Twitter;
//API Keys
...
$client = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$application = new Application();
$application->add(new TwitterCommand($client));
$application->run();
然后在我的TwitterCommand.php中,我有以下内容:
<?php
namespace Source\Commands;
use Twitter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class TwitterCommand extends Command
{
private $client;
public function __construct(Twitter $client)
{
parent::__construct();
$this->client = $client;
}
protected function configure()
{
$this
->setName('freq:tweet')
->setDescription('Show the tweets')
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// Retrieve the user's timeline
$tweets = $twitter->getTimeline(array(
'count' => 5
));
// Or retrieve the timeline using the generic query method
$response = $twitter->query('statuses/user_timeline', 'GET', 'json', $parameters);
$tweets = json_decode($response->getContent());
$output->writeln($tweets);
}
}
问题是我遇到“致命错误:在C:...中找不到类'Source \\ Commands \\ TwitterCommand'”,并且该错误在以下行中发送:
$application->add(new TwitterCommand($client));
关于我在做什么错的任何想法吗?
如果要自动加载您的课程,则必须放弃PSR-0标准。 在项目的composer.json中,您可能定义了以下内容:
"autoload": {
"psr-0": { "": "src/" }
},
您的类文件路径应为src / Source / Commands / TwitterCommand.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.