Symfony:致命错误:在app / console中找不到类

时间:2015-03-28 00:10:10

标签: php symfony 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);
}
}

问题是我遇到了致命错误:Class&#39; Source \ Commands \ TwitterCommand&#39;在C中找不到:......&#39;并在此行中发送错误:

$application->add(new TwitterCommand($client));

关于我做错了什么的任何想法?

1 个答案:

答案 0 :(得分:4)

如果您希望自动加载课程,则必须选择PSR-0标准。在项目的composer.json中,你可能已经定义了类似的东西:

"autoload": {
    "psr-0": { "": "src/" }
},

您的类文件路径应为src / Source / Commands / TwitterCommand.php

相关问题