2017-02-28 5 views
1

Silex를 사용하여 콘솔 명령을 실행하려고하면이 오류가 발생합니다.Silex 명령이 실패했습니다.

PHP Error: Class 'Testing\Command\TestingCommand' 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 Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TestingCommand" from namespace "Testing\Command". 
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 파일을 가지고 있습니다. 콘솔은 부트 스트랩을로드하고 콘솔 파일에 내가 좋아하는 어떤 것을 가지고 명령이 SRC/명령/TestingCommand.php

I에 위치한

{ 
    "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/" 
     } 
    } 
} 

#!/usr/bin/env php 
<?php 

set_time_limit(0); 

$app = require_once __DIR__ . '/bootstrap.php'; 

$application = $app['console']; 
$app['console']->add(new \Testing\Command\TestingCommand()); 
$application->run(); 

작곡가 파일을 Silex에 초보자이고 문제를 일으킬 수 있는지 알 수 없습니다. 고맙습니다.

+0

을 변경 한 후

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

를? 질문에있는 composer.json의 내용을 추가하십시오. –

+0

작곡가 파일 정보로 질문을 업데이트했습니다. –

답변

1

오토로더가 명령 클래스를로드 할 수 없습니다. composer.json의 autoload 섹션에 따르면이 클래스의 클래스 이름 파일은 src/Testing/Command/TestingCommand.php에 있어야합니다. 그래서 당신은이 위치에이 파일을 이동하거나 composer.json에서 다른 검색 디렉토리를 설정할 수 있습니다 :이 명령 클래스가 위치한 composer.json 실행 composer dump-autoload

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

+0

나는 dump-autoload를 실행하고 이것을 가지고 있습니다 ->'비어 있지 않은 PSR-4 접두어는 네임 스페이스 분리 자로 끝나야합니다 .' btw : psr-4 내부의 첫 줄 뒤에 ","이 있다고 생각합니다. –

+0

''\\ Command \\ "테스트 중 :"src/Command/"'제 답변을 고쳤습니다 –

+0

대단히 감사합니다 :) –