命名空间 - 当移动到src目录时,composer无法加载类

时间:2013-02-24 20:13:05

标签: php namespaces composer-php

我正在准备php库并决定稍微重新组织目录结构 一切都在运作,并从这个结构:

This was working

我决定进入:

enter image description here

我重新生成了自动加载(php composer.phar dumpautoload),运行测试并获得:

PHP Fatal error:  Class 'Compa\Components\Finder\Objects' not found in /home/mrok/php/top/pac-b-test/tests/Finder/ObjectsTest.php on line 15
PHP Stack trace:
PHP   1. {main}() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/composer/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/composer/bin/phpunit:65
PHP   3. PHPUnit_TextUI_Command->run() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:346
PHP   6. PHPUnit_Framework_TestSuite->run() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:705
PHP   7. PHPUnit_Framework_TestSuite->runTest() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745
PHP   8. PHPUnit_Framework_TestCase->run() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775
PHP   9. PHPUnit_Framework_TestResult->run() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:769
PHP  10. PHPUnit_Framework_TestCase->runBare() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648
PHP  11. PHPUnit_Framework_TestCase->runTest() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:824
PHP  12. ReflectionMethod->invokeArgs() /home/mrok/php/top/pac-b-test/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:969
PHP  13. Compa\Components\Test\Finder\ObjectsTest->find() /home/mrok/php/top/pac-b-test/tests/Finder/ObjectsTest.php:0

autload_namespaces包含:

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

return array(
    'Symfony\\Component\\Yaml' => $vendorDir . '/symfony/yaml/',
    'Compa\\Components' => $baseDir . '/src/',
);

知道可能出现什么问题吗?我应该改变包含路径吗?我不这么认为,否则使用这个库的每个人都必须这样做。

1 个答案:

答案 0 :(得分:1)

要使其有效PSR-0,您的文件应位于:

src/Compa/Components/Finder/Objects.php

但不知道为什么它使用以前的结构...