簡體   English   中英

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM