use PHPExcel with composer and Symfony2.2

我们两清 提交于 2019-11-30 22:54:10
Seldaek

Regarding your primary question, the problem is that once the package is installed, if you update the definition and add autoload stuff, then running composer update will not change anything. Composer still has the old package that was already installed in its "cache", so it uses that to generate the autoload and that fails.

To resolve this you should remove the vendor/PHPOffice/PHPExcel directly and run composer update, which will reinstall it with the latest information from your composer.json, including autoload, etc. You should specify autoloading as such:

"repositories": [{
    "type": "package",
    "package": {
        "name": "PHPOffice/PHPExcel",
        "version": "1.8.0",
        "source": {
            "url": "https://github.com/PHPOffice/PHPExcel.git",
            "type": "git",
            "reference": "1.8.0"
        },
        "autoload": {
            "psr-0": {
                "PHPExcel": "Classes/"
            }
        }
    }
}],
"require": {
    "PHPOffice/PHPExcel": "1.8.*",
    ...

Regarding the secondary question and '' vs 'PHPExcel': '' just says that any namespace can be found in this directory. That means the autoloader will always scan this directory to find classes, which is convenient but slower than mapping namespaces to directories explicitly. So both work, but the more specific form is preferred, especially in packages you publish publicly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!