使用PHPExcel与作曲家和Symfony2.2 [英] use PHPExcel with composer and Symfony2.2

查看:142
本文介绍了使用PHPExcel与作曲家和Symfony2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SO上找到这个:如何正确使用PHPExcel与Symfony 2



这样可以工作,但我想用它与作曲家一起使用。
我已经解决了第一部分:为特殊标记加载PHPExcel(最后一个稳定版本)



我找不到如何获取标记使用以下语法:

 repositories:[
{
type:vcs
url:https://github.com/umpirsky/SyliusAssortmentBundle
}
]

所以我使用 Package 符号:

我发现了 / code>应该是github上的标签名称。
版本不能是相同的值(PHPExcel_1.7.8)。看起来不允许使用字母字符,所以只有版本作为数字(1.7.8)

 repositories:[ {
type:package,
package:{
name:PHPOffice / PHPExcel,
version:1.7.8
source:{
url:https://github.com/PHPOffice/PHPExcel.git,
type:git,
reference:PHPExcel_1.7.8
}
}
}]

下一步我没有解决。我尝试了自动加载的每个组合:psr-0,classmap,不同的路径,相对于project / vendor / phpexcel,每次更新composer,但没有工作。



只有工作,如果我把这行

  $ loader-> add('PHPExcel',__DIR __。'/ .. /供应商/ PHPOffice / PHPExcel / Classes'); 

到app / autoload.php。我发现,第一个字符串( PHPExcel )也可以是一个空字符串:''

如果我使用 PHPExcel ''?有什么不同?



所以我的主要问题是,我如何避免将这一行写入autoload.php,将等效的命令放入我的项目的composer.json?

$关于你的主要问题,问题是一旦软件包被安装,如果你更新定义和添加自动加载的东西,然后运行<$ c

$ c> composer update 将不会更改任何内容。 Composer仍然具有已经安装在其缓存中的旧包,因此它使用它来生成自动加载并且失败。



要解决此问题,您应该直接删除供应商/ PHPOffice / PHPExcel ,并运行 composer更新,它将使用composer.json中的最新信息(包括自动加载等)重新安装它。您应该如下指定自动加载:

 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。*,
...

c $ c>'' vs 'PHPExcel'''命名空间可以在这个目录中找到。这意味着自动装载器将总是扫描这个目录来查找类,这是方便,但比名称空间到目录显式地映射慢。所以这两个工作,但更具体的形式是首选,特别是在你公开发布的包。


I found this on SO: How to use PHPExcel correctly with Symfony 2

This works, but I want to use it with composer. The first part I already solved: to load PHPExcel for a special tag (the last stable release)

I don't find out how to fetch a tag with this syntax:

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/umpirsky/SyliusAssortmentBundle"
    }
]

So I use the Package notation:
I found out, the reference should be the tag name on github. And the version cannot be the same value (PHPExcel_1.7.8). Seems that alphabetical characters are not allowed, so it's only the version as a number (1.7.8)

"repositories": [{
    "type": "package",
    "package": {
        "name": "PHPOffice/PHPExcel",
        "version": "1.7.8",
        "source": {
            "url": "https://github.com/PHPOffice/PHPExcel.git",
            "type": "git",
            "reference": "PHPExcel_1.7.8"
        }
    }
}]

The next step I didn't solve. I tried out every combination for the autoloading: psr-0, classmap, different paths, relative to project/vendor/phpexcel, update composer everytime, but nothing worked.

It only works, if I put this line

$loader->add('PHPExcel', __DIR__.'/../vendor/PHPOffice/PHPExcel/Classes');

into the app/autoload.php. I found out, that the first string (PHPExcel) can also be an empty string: ''.
Is there a differnece if I use PHPExcel or ''?

So my primary question is, how can I avoid to write this line into the autoload.php, put the equivalent commands into my project's composer.json?

解决方案

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.

这篇关于使用PHPExcel与作曲家和Symfony2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆