[英]Symfony: Fatal Error: Class not found in app/console
I'm trying to get commands from command line to work using symfony. 我正在尝试从命令行获取命令以使用symfony进行工作。 I have the following folder structure:
我具有以下文件夹结构:
Now in my console file I have the following code: 现在在我的控制台文件中,我有以下代码:
#!/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();
And then in my TwitterCommand.php i have the following: 然后在我的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);
}
}
The problem is I'm getting a 'Fatal error: Class 'Source\\Commands\\TwitterCommand' not found in C:...' and the error is sent in this line: 问题是我遇到“致命错误:在C:...中找不到类'Source \\ Commands \\ TwitterCommand'”,并且该错误在以下行中发送:
$application->add(new TwitterCommand($client));
Any idea on what am I doing wrong? 关于我在做什么错的任何想法吗?
If you want your class to be autoloaded you have to fallow PSR-0 standard. 如果要自动加载您的课程,则必须放弃PSR-0标准。 In the composer.json of your project you have probably defined something like that:
在项目的composer.json中,您可能定义了以下内容:
"autoload": {
"psr-0": { "": "src/" }
},
Your class file path should be src/Source/Commands/TwitterCommand.php 您的类文件路径应为src / Source / Commands / TwitterCommand.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.