简体   繁体   English

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

[英]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: 我具有以下文件夹结构:

  • app console 应用控制台
  • src SRC
    • Source 资源
      • Commands twitterCommand.php 命令twitterCommand.php

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.

相关问题 致命错误:第16行的app / console中找不到类&#39;Symfony \\ Component \\ Console \\ Input \\ ArgvInput&#39; - Fatal error: Class 'Symfony\Component\Console\Input\ArgvInput' not found in app/console on line 16 Symfony3:致命错误:在 .\\bin\\console 中找不到“AppKernel”类 - Symfony3: Fatal error: Class 'AppKernel' not found in .\bin\console PHP 致命错误:未捕获错误:Class 未找到“Symfony\Component\Console\Application” - PHP Fatal error: Uncaught Error: Class 'Symfony\Component\Console\Application' not found 找不到Symfony 1.4致命错误&#39;myUser&#39;类 - Symfony 1.4 Fatal error Class 'myUser' not found PHP 致命错误:未捕获错误:Class 'Normalizer' not found in /usr/share/php/Symfony/Component/Console/Helper/Helper.ZE1BFD762321E409963CEE4AC0B6ECZ8 - PHP Fatal error: Uncaught Error: Class 'Normalizer' not found in /usr/share/php/Symfony/Component/Console/Helper/Helper.php PHP致命错误:未捕获的错误:在Symfony上找不到类“ DOMDocument” - PHP Fatal error: Uncaught Error: Class 'DOMDocument' not found on Symfony 致命错误:找不到“ App \\ PDO”类 - Fatal error: Class 'App\PDO' not found in Symfony 2.3.5致命错误:在服务器上找不到类“ResourceBundle” - Symfony 2.3.5 Fatal error: Class 'ResourceBundle' not found on Server 带有Symfony致命错误的PHPUnit:找不到类&#39;Doctrine \\ Bundle \\ DoctrineBundle \\ DoctrineBundle&#39; - PHPUnit with Symfony Fatal error: Class 'Doctrine\Bundle\DoctrineBundle\DoctrineBundle' not found Symfony:致命错误:找不到类'PHPUnit_Framework_TestCase' - Symfony: Fatal error: Class 'PHPUnit_Framework_TestCase' not found in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM