本文介绍了使用Composer安装时如何配置tcpdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的旧版PHP代码包括tcpdf( https://github.com/tecnickcom/TCPDF )代码库的一部分.

Our legacy PHP code includes tcpdf (https://github.com/tecnickcom/TCPDF) as part of the code base.

我试图将其移到 vendor 文件夹中,所以我将Composer添加到项目中,将TCPDF添加到 composer.json 中并进行了更新.

I am trying to move it out to a vendor folder, so I added Composer to the project, added TCPDF to composer.json and updated.

但是根据我们的文档, config/tcpdf_config.php 文件已在我们的代码库(自定义PDF作者名称等)中进行了修改,因此是正确的:/www.tcpdf.org/installation.php"rel =" nofollow> http://www.tcpdf.org/installation.php

But the config/tcpdf_config.php file is modified in our code base (custom PDF author name etc.), and rightfully so, according to the docs: http://www.tcpdf.org/installation.php

现在,我不确定修改 vendor/tecnick.com/tcpdf/config/tcpdf_config.php 是个好主意,因为每次更新时Composer都可能会覆盖它.另外,tcpdf文档中也没有关于Composer的字眼.

Now, I'm not sure it's a good idea to modify vendor/tecnick.com/tcpdf/config/tcpdf_config.php because it might be overwritten by Composer any time I update. Also, there is not a word about Composer in the tcpdf docs.

在允许Composer更新的同时配置tcpdf(或通过Composer使用的任何第三方库)的正确解决方案是什么?

What is the right solution to configure tcpdf (or any third-party library used through Composer, for that matter) while allowing Composer updates?

推荐答案

注入配置的方法是先定义所有常量,然后再接触第一个TCPDF类.

The way you are supposed to inject your configuration is to define all the constants first before ever touching the first TCPDF class.

请确保还将常量 K_TCPDF_EXTERNAL_CONFIG 设置为true.这将阻止自动配置搜索正在讨论的文件.(请参见此文件的第60行: http://sourceforge.net/p/tcpdf/code/ci/master/tree/tcpdf_autoconfig.php )

Make sure to also set the constant K_TCPDF_EXTERNAL_CONFIG to true. This will prevent the autoconfiguration to search for the file you were talking about. (See line 60 of this file here: http://sourceforge.net/p/tcpdf/code/ci/master/tree/tcpdf_autoconfig.php)

这在文档中很好地隐藏了,但是我发现了这一点: http://www.tcpdf.org/doc/code/example__019_8php.html

This is well hidden in the documentation, but I found this: http://www.tcpdf.org/doc/code/example__019_8php.html

  1. 将原始的 tcpdf_config.php 复制到您的项目中,例如 src/tcpdf_config.php .
  2. 在配置副本的开头添加 define('K_TCPDF_EXTERNAL_CONFIG',true); ,并根据需要修改其余配置.
  3. 编辑您的 composer.json 并添加/更新 autoload 部分:
  1. Copy the original tcpdf_config.php somewhere to your project, for example src/tcpdf_config.php.
  2. Add define('K_TCPDF_EXTERNAL_CONFIG', true); at the beginning of your config copy and modify the rest of the config to your needs.
  3. Edit your composer.json and add/update autoload section:
...
"autoload": {
  ...
  "files": [
    "src/tcpdf_config.php",
    ...
  ]
}
...
  1. 使用 composer dump-autoload 重新生成作曲家自动加载器.
  1. Regenerate the composer autoloader using composer dump-autoload.

这篇关于使用Composer安装时如何配置tcpdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 13:52