Symfony:致命错误:在应用程序/控制台中找不到类


Symfony: Fatal Error: Class not found in app/console

我正在尝试从命令行获取命令,以便使用symfony工作。我有以下文件夹结构:

  • 应用程序控制台
  • src
    • 来源
      • 命令twitterCommand.php

现在,在我的控制台文件中,我有以下代码:

#!/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