Silex命令失败



我尝试使用silex运行控制台命令。

PHP Error:  Class 'TestingCommandTestingCommand' not found in /var/www/testCmd/app/console on line 9
PHP Stack trace:
PHP   1. {main}() /var/www/testCmd/app/console:0
PHP Fatal error:  Uncaught SymfonyComponentDebugExceptionClassNotFoundException: Attempted to load class "TestingCommand" from namespace "TestingCommand".
Did you forget a "use" statement for another namespace? in /var/www/testCmd/app/console:9
Stack trace:
#0 {main}
  thrown in /var/www/testCmd/app/console on line 9

我有app/console.php和app/bootstrap.php文件。控制台正在加载bootstrap,在控制台文件中,我有一些类似:

#!/usr/bin/env php
<?php
set_time_limit(0);
$app = require_once __DIR__ . '/bootstrap.php';
$application = $app['console'];
$app['console']->add(new TestingCommandTestingCommand());
$application->run();

作曲家文件

{
    "name": "testing/Command",
    "require": {
        "knplabs/console-service-provider": "^2.0",
        "silex/silex": "^2.0",
        "symfony/monolog-bridge": "^3.1",
        "doctrine/common": "^2.6",
        "doctrine/dbal": "^2.5"
    },
    "autoload": {
        "psr-4": {
            "\": "src/"
        }
    }
}

该命令位于src/command/testingcommand.php

我是Silex的新手,我不知道会导致问题。谢谢

自动加载器无法加载命令类。根据coposer.json和类名称文件的自动加载部分,该类别应位于src/Testing/Command/TestingCommand.php中。因此,您可以在此位置移动此文件或在composer.json中设置另一个搜索目录:

"autoload": {
    "psr-4": {
        "Testing\Command\": "src/Command/"
        "\": "src/"
    }
}

更改Composer.json运行composer dump-autoload

https://getcomposer.org/doc/01-basic-usage.md#autoloading

相关内容

  • 没有找到相关文章

最新更新