dongxieyi9115 2013-11-15 22:57
浏览 83
已采纳

设置扩展TCPDF的类

In Symfony I'm using TCPDF package for creating PDF documents and I have it installed via composer. I need to modify TCPDF class a little before I use it in production, so I created MyPDF class that extends TCPDF class and that is stored in the same file as original class (Symfony-project/vendor/tecnick.com/tcpdf/tcpdf.php).

Problem is, that every time I update composer and new version of TCPDF package is installed, file tcpdf.php is being replaced, so class MyPDF disappears. What is consider as best practice for creating and storing such classes?

  • 写回答

1条回答 默认 最新

  • dtiopy6088 2013-11-15 23:08
    关注

    You should not work in the vendor/ directory. It is preserved for external code only. Here is what you can do:

    • You could fork the TCPDF repository and apply their changes. Afterwards you just use your own fork of that repo. Downside of this is that you might miss out on important bug-fixes. If the patch you apply to the code is important for anyone you are also welcome to open a pull-request to merge your fix back into the main repository.
    • You could create a service that extends the TCPDF classes. Here is my service definition using this repository:

      <service id="pdfgenerator" class="TCPDF">
          <file>%kernel.root_dir%/../vendor/r1pp3rj4ck/tcpdf/tcpdf.php</file>
          <argument key="orientation">P</argument>
          <argument key="unit">mm</argument>
          <argument key="format">A4</argument>
      </service>
      

      Your can extend this service as you like.

    Edit:

    See the Github HowTo on how to fork a repository. After you have your own fork you can edit the code to your needs. After you are done and your repository is ready you just include your own repository instead of the current TCPDF repository. See the composer docs for more information. You should add something like this to your composer.json:

    {
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/..."
            }
         ],
         "require": {
             ".../tcpdf": "dev-master"
         }
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画