1

我已经使用 composer 在本地设置了一个项目来自动加载我的供应商和模块。这是在运行 Nginx 的 Windows XP 机器上完成的。

当我将所有内容同步到生产服务器并运行 LAMP 时,自动加载器停止工作,并且我调用的每个类都找不到。

由于这是一个共享主机,我无法运行 composer.phar update 来尝试刷新类映射命名空间。

任何人都知道可能会发生什么?

+信息:

<?php

// autoload_namespaces.php generated by Composer

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

return array(
    'Zend\\' => $vendorDir . '/zendframework/zendframework/library/',
    'ZendTest\\' => $vendorDir . '/zendframework/zendframework/tests/',
    'Symfony\\Component\\Console' => $vendorDir . '/symfony/console/',
    'Doctrine\\ORM' => $vendorDir . '/doctrine/orm/lib/',
    'Doctrine\\DBAL' => $vendorDir . '/doctrine/dbal/lib/',
    'Doctrine\\Common' => $vendorDir . '/doctrine/common/lib/',
    'DoctrineORMModule\\' => $vendorDir . '/doctrine/doctrine-orm-module/src/',
    'DoctrineORMModuleTest\\' => $vendorDir . '/doctrine/doctrine-orm-module/tests/',
    'DoctrineModule\\' => $vendorDir . '/doctrine/doctrine-module/src/',
    'DoctrineModuleTest\\' => $vendorDir . '/doctrine/doctrine-module/tests/',
    'Application\\' => $baseDir . '/module/Application/src',
);



<?php

// autoload_classmap.php generated by Composer

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

return array(
);

$loader 返回:

Composer\Autoload\ClassLoader Object
(
    [prefixes:Composer\Autoload\ClassLoader:private] => Array
        (
            [Zend\] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/zendframework/zendframework/library/
                )

            [ZendTest\] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/zendframework/zendframework/tests/
                )

            [Symfony\Component\Console] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/symfony/console/
                )

            [Doctrine\ORM] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/doctrine/orm/lib/
                )

            [Doctrine\DBAL] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/doctrine/dbal/lib/
                )

            [Doctrine\Common] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/doctrine/common/lib/
                )

            [DoctrineORMModule\] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/doctrine/doctrine-orm-module/src/
                )

            [DoctrineORMModuleTest\] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/doctrine/doctrine-orm-module/tests/
                )

            [DoctrineModule\] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/doctrine/doctrine-module/src/
                )

            [DoctrineModuleTest\] => Array
                (
                    [0] => /home/XXXX/public_html/vendor/doctrine/doctrine-module/tests/
                )

            [Application\] => Array
                (
                    [0] => /home/XXXX/public_html/module/Application/src
                )

        )

    [fallbackDirs:Composer\Autoload\ClassLoader:private] => Array
        (
        )

    [useIncludePath:Composer\Autoload\ClassLoader:private] => 
    [classMap:Composer\Autoload\ClassLoader:private] => Array
        (
        )

)

++信息:

spl_autoload_functions:

Array
(
    [0] => Array
        (
            [0] => Composer\Autoload\ClassLoader Object
                (
                    [prefixes:Composer\Autoload\ClassLoader:private] => Array
                        (
                            [Zend\] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/zendframework/zendframework/library/
                                )

                            [ZendTest\] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/zendframework/zendframework/tests/
                                )

                            [Symfony\Component\Console] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/symfony/console/
                                )

                            [Doctrine\ORM] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/doctrine/orm/lib/
                                )

                            [Doctrine\DBAL] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/doctrine/dbal/lib/
                                )

                            [Doctrine\Common] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/doctrine/common/lib/
                                )

                            [DoctrineORMModule\] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/doctrine/doctrine-orm-module/src/
                                )

                            [DoctrineORMModuleTest\] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/doctrine/doctrine-orm-module/tests/
                                )

                            [DoctrineModule\] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/doctrine/doctrine-module/src/
                                )

                            [DoctrineModuleTest\] => Array
                                (
                                    [0] => /home/XXXX/public_html/vendor/doctrine/doctrine-module/tests/
                                )

                            [Application\] => Array
                                (
                                    [0] => /home/XXXX/public_html/module/Application/src
                                )

                        )

                    [fallbackDirs:Composer\Autoload\ClassLoader:private] => Array
                        (
                        )

                    [useIncludePath:Composer\Autoload\ClassLoader:private] => 
                    [classMap:Composer\Autoload\ClassLoader:private] => Array
                        (
                        )

                )

            [1] => loadClass
        )

)
4

1 回答 1

1

解决方案是 str 在所有模块自动加载器中用 / 替换命名空间中的所有 \。

所以这:

public function getAutoloaderConfig() {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/', __NAMESPACE__),
                ),
            ),
        );
    }

将使一切在 LAMP 机器上按预期工作。

于 2013-02-22T15:59:55.213 回答