composer autoload not working on production server

2019-08-13 20:09发布

I've setup a project localy using composer to autoload my vendors and modules. This is done on a Windows XP machine running Nginx.

When I sync everything to my production server, running LAMP, the autoloader stops working and every class i call its not found.

Since this is a shared host i cant run composer.phar update to try to refresh the classmap namespace.

Anyone knows what might be happening?

+INFO:

<?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 returned:

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
        (
        )

)

++INFO:

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
        )

)

1条回答
闹够了就滚
2楼-- · 2019-08-13 20:33

The solutions was str replacing all the \ from the namespaces with / in all the modules autoloaders.

So,this:

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

will get everything working as intended on a LAMP machine.

查看更多
登录 后发表回答