简体   繁体   English

如何在Symfony 2.1中的composer.json中提供第三方库并在我们的包中访问库?

[英]How to give third party libraries in composer.json in Symfony 2.1 and access library in our bundle?

I need to integrate TCPDF as third party library in Symfony 2.1. 我需要将TCPDF集成为Symfony 2.1中的第三方库。

I tried in composer.json like 我在composer.json中尝试过

"repositories": [
    {
        "type": "vcs",
        "url": "git://tcpdf.git.sourceforge.net/gitroot/tcpdf/tcpdf"
    }
],
"require": {
    "tcpdf/tcpdf":"*"
},

But it gives an error The requested package tcpdf * could not be found. 但它给出了错误The requested package tcpdf * could not be found.

How to give third party libraries correct in composer.json file? 如何在composer.json文件中更正第三方库?

TCPDF library don't follow namespaces, so how we can access this library in our bundle? TCPDF库不遵循命名空间,那么我们如何在捆绑中访问这个库?

The reason it's not found is that the package name in the tcpdf repo is tecnick.com/tcpdf , so that's what you should require. 找不到它的原因是tcpdf repo中的软件包名称是tecnick.com/tcpdf ,这就是你应该要求的。

That said, since it's available on packagist you don't need to add the vcs repository at all in your composer.json. 也就是说,因为它可以在packagist上使用,所以你根本不需要在composer.json中添加vcs存储库。

Packagist上有几个与TCPDF相关的软件包 - 其中一些是与Symfony集成的软件包。

Since tcpdf does not support composer you need to use the package repository. 由于tcpdf不支持composer,因此您需要使用包存储库。 The docs for this is available at: 有关此文档,请访问:

http://getcomposer.org/doc/05-repositories.md#package-2 http://getcomposer.org/doc/05-repositories.md#package-2

Do note that their example configuration has both dist and source where source is what you need. 请注意,他们的示例配置包含distsource ,其中source是您所需要的。 You will probably also need to configure the autoloading to match that of tcpdf. 您可能还需要配置自动加载以匹配tcpdf。 You can find documentation on that on the composer website as well. 您也可以在作曲家网站上找到有关该文档的文档。

A good thing would also be to send the tcpdf authors an email and ask them if they don't mind adding a composer.json. 一件好事也是向tcpdf作者发送一封电子邮件,询问他们是否不介意添加composer.json。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM